问题描述
出于向后兼容的原因,我有一个Rectangle2d和一个Rectangle3d。这样做时,类的“ transform”字段的类型应从Transform2d更改为Transform2d的派生版本Transform3d。 这是一个简化的示例:
class Transform2
{
protected float positionX;
protected float positionY;
}
class Transform3 : Transform2
{
protected float positionZ;
}
class Rectangle2d
{
protected Transform2 transform;
}
class Rectangle3d : Rectangle2d
{
// Does not work: Just hides Rectangle2d.transform
protected new Transform3 transform;
}
我不喜欢的一种解决方案是不使用Transform类,而直接使用字段:
class Rectangle2d
{
protected float positionX;
protected float positionY;
}
class Rectangle3d : Rectangle2d
{
protected float positionZ;
}
在我眼中,当第二种方法有效并且第一种方法只是第二种方法并带有一些聚束时,应该有一个干净的解决方案。至少希望如此。
版本:.NET Framework 4.6.1
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)