c# - Correct approach to storing different types in two subclasses -
i working in c# , i'm trying write abstracttriangle hierarchy 2 subclasses: triangle , specialtriangle.
triangles made of lines, specialtriangles made of speciallines!
i can think of number of ways store lines in triangles:
- abstracttriangle contains list of abstractline
- abstracttriangle contains list of iline
- itriangle has accessors list of iline, triangle , specialtriangle responsible own lists of line or specialline
what correct, elegant way of handling these hierarchies?
do need sacrifice triangles returning concrete typed lines make work properly?
use generics instead of inheritance:
class triangle<t> t: iline { list<t> edges; ··· }
and instantiate as
triangle<line>
or
triangle<specialline>
Comments
Post a Comment