我需要一个类似于set-theory的差异运算符\
的行为。
我试图得到一些friend
类行为,因为我有以下情况:
public interface IRead
{
List<string> GetInnerResource();
}
public interface IWrite()
{
bool SetInnerResource();
}
public interface IFull:IRead,IWrite{
void SomeMethod();
}
public Consumer:IFull // IFull \ IWrite
{
private IFull access; // IFull\IWrite
public List<string> GetInnerResource()=>this.access.GetInnerResource();
public void SomeMethod()=>this.acces.SomeMethod(); // i need this
public bool SetInnerResource(){...}//--i do not want this here !
}
public Admin:IFull
{
private IFull access;
public List<string> GetInnerResource()=>this.access.GetInnerResource();
public bool SetInnerResource()=>this.access.SetInnerResource();
public void SomeMethod()=>this.access.SomeMethod();
}
如你所见,我有3
接口(IRead
,IWrite
,IFull
),其中第三个来自第一个2
,并有另一种方法。
我有两个类Consumer
和Admin
其中:
-Consumer needs to implement IFull \ IWrite
-Admin needs IFull
由于我的具体类都将实现委托给内部字段,因此问题在于Consumer
类的内部字段,因为它需要实现something
的IFull\IWrite
通常在C++
我会用friend
类来解决这个问题,这个类可以完全访问类,同时使用Read
用于所有其他类。我不能这样做。
我有什么选择?
我需要ISomething: {IFull\IWrite}
类的接口Consumer
P.Sazxswpoi
一个快速而简单的解决方案是从IFull接口拆分层次结构,并有3个独立的接口,可以根据Consumer或Admin类的使用需求派生