class TypeA
{
public TypeA Copy () { ... }
public bool IsEqual(TypeA mytypeA) { ... }
public bool IsSame(TypeA mytypeA) { ... }
...
}
class TypeACollection : List<TypeA>
{
public bool IsSame (TypeACollection typeAs)
{
if (Count != typeAs.Count)
return false;
return this[0].IsSame(typeAs[0]);
}
...
}
TypeB、TypeC は TypeA と同様の関数 Copy/IsEqual/IsSame を持っています。TypeBCollection、TypeACollection には、同様の IsSame があります。例外は、TypeBCollection は TypeB.IsSame を使用し、TypeCCollection は TypeC.IsSame を使用します。
今、2 つの新しいクラスを追加する予定です: LocData と LocDataCollection
class LocData
{
public virtual TypeA Copy () { ... }
public virtual bool IsEqual(TypeA mytypeA) { ... }
public virtual bool IsSame(TypeA mytypeA) { ... }
...
}
class LocDataCollection<T> : List<LocData> where T: LocData
{
public bool IsSame (LocDataCollection<T> typeAs)
{
if (Count != typeAs.Count)
return false;
return this[0].IsSame(typeAs[0]);
}
...
}
既存のコードを書き直し、
class TypeA : LocData
{
public new TypeA Copy () { ... }
public new bool IsEqual(TypeA mytypeA) { ... }
public new bool IsSame(TypeA mytypeA) { ... }
...
}
class TypeACollection : ???
{
???
// so I can remove IsSame here,
// when I call IsSame, it will use one from LocDataCollection and still call
// TypeA.IsSame
...
}
今、私は抽象/仮想/ジェネリック/...で迷子になりましたが、どれが最善の方法ですか?