【发布时间】:2009-06-30 18:05:24
【问题描述】:
在两个不同的程序集中有以下类:
class Member
{
public string Label {get;set;}
// Lots of other fields...
public double Thickness {get;set;}
public double Width {get;set;}
public double Length {get;set;}
public double GetVolume ()
{
return Thickness * Width * Length;
}
// Other methods
}
class OtherMember
{
public string CompositeLabel {get;set;}
// Lots of other fields (not related to other class: Member)
public double Thickness {get;set;}
public double Width {get;set;}
public double Length {get;set;}
public double GetVolume ()
{
return Thickness * Width * Length;
}
// Other methods
}
我想将厚度、宽度、长度属性和 GetVolume 方法重构为另一个类(尺寸?)作为 DRY...
然后我可以在这些类中拥有一个字段/属性来访问维度实例。
这是一个好方法吗?
我已经简洁地阅读了有关使用接口而不是具体类的信息,我应该从接口继承吗?
另外,不变性呢?
我觉得我经常迷失在正确地设置我的域类。有人对此有什么建议吗?
【问题讨论】:
标签: c# refactoring interface model