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:

  1. abstracttriangle contains list of abstractline
  2. abstracttriangle contains list of iline
  3. 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

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -