我想将 protected 方法的访问限制为仅某些继承的类。
例如,有一个基类,例如
TBase = Class
Protected
Method1;
Method2;
Method3;
Method4;
End;
我有两个从 TBase 派生的类
TDerived1 = Class(TBase)
//Here i must access only Method1,Method2 and Method3
End;
TDerived2 = Class(TBase)
//Here i must access only Method3 and Method4
End;
那么可以吗 当我使用 TDerived1 的对象时,仅访问 Method1、Method2 和 Method3 当我使用TDerived2的对象时方法3和方法4
最佳答案
没有办法做到这一点。如果一个方法是 protected ,那么所有后代类都可以访问它。如果您有两组可以轻松划分的独立功能,您可能需要重新考虑您的类设计。
关于delphi - 将 protected 部分中的方法访问限制为少数类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2990850/