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

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -