日期:2014-05-18  浏览次数:20789 次

类成员的可见性
设计一个类时,能否让其中一些成员只对某些特定类可见?

------解决方案--------------------
应该不能。
------解决方案--------------------
不行的吧
除非你让工厂继承类
------解决方案--------------------
可以考虑使用接口来实现:

------定义接口及类
class A : IA
{
public void a()
{
throw new Exception( "The method or operation is not implemented. ");
}

void IA.b()
{
throw new Exception( "The method or operation is not implemented. ");
}
}
class B : IA
{
void IA.a()
{
throw new Exception( "The method or operation is not implemented. ");
}

public void b()
{
throw new Exception( "The method or operation is not implemented. ");
}
}

--------使用类--------
A aa = new A();
aa.a();//只看到a方法,看不到b方法
B bb = new B();
bb.b();//只看到b方法,看不到a方法

------解决方案--------------------
楼上的很经典
------解决方案--------------------
拜楼上的
------解决方案--------------------
想不太复杂了嘛!


访问属性设置成:protected !