我有 2 个不同的小部件,它们共享 10 个相同的成员。但是它们也有 2 个阶段。每个阶段都有其他阶段没有的特定成员。
public class widget
private _id as integer
private _engravedId as string
private _stage as WidgetStage
private _wig as IWidget
end class
public interface IWidget
Calculate()
end interface
public class Twidget
implemets IWidget
private t as integer
private b as double
private d as double
end class
public class Rwidget
implemenents IWidget
private y as integer
private x as double
private b as double
end class
如果我在我的类中声明一个 Iwidget,那么我将不得不对其进行强制转换以访问派生类变量。有没有更好的办法?