Multiple Inheritance Solution - with the ability to change lvl protection

I need a solution for multiple inheritance. I know that I can use interfaces. This would be a good solution, but ... ... I need the ability to change the level of protection, but the interface fields must be public ...

For instance:

I have

interface IInterface_1 { string field_1{set;get;} string field_2{set;get;} } interface IInterface_2 { string field_3{set;get} string field_4{set;get} } 

And in the main class I need to hide some fields

 class MainClass : IInterface_1, IInterface_2 { public string field_1{set;get;} private string field_2{set;get;} public string field_3{set;get} public string field_4{set;get} } 

Do you have a solution for this?

+4
source share
2 answers

[Copied from Robson's question and his rejected change in response to Marc]

My decision:

 public class PermissionDeniedException : Exception {} class MainClass : IInterface_1, IInterface_2 { public string field_1{set;get;} private string field_2{set;get;} string IInterface_1.field_2 { get {throw new PermissionDeniedException();} set {throw new PermissionDeniedException();} } public string field_3{set;get} public string field_4{set;get} } 
+1
source

Explicit interface implementation:

  class MainClass : IInterface_1, IInterface_2 { public string field_1{get;set;} public string field_3{get;set;} public string field_4{get;set;} private string field2; string IInterface_1.field_2 { get {return field2;} set {field2 = value;} } } 
+6
source

All Articles