4
Reply

Generics & Inheritence

Tyler Copple

Tyler Copple

Jan 25 2008 1:00 PM
6.4k
I'm designing an object model which needs a few constraints and I'm not sure how exactly to do what I want in C#, any help is appreciated.

Basically
Class A {...}
Class B : A {...}
Class C : B {...}
Class AGroup : Collection<A> {...}
Class BGroup : AGroup {...}
Class CGroup : BGroup {...}

The feature I need is to make sure that BGroup's collection only has B objects in it, but retains all the methods and members from AGroup.

While CGroups's collection only has C objects in it but has both A and B methods and members accessible.

Strong typing which gets stronger each level of inheritance.

Is this possible?  
Thanks in advance,
Tyler Copple

Upload Source Code  Select only zip and rar file.
Answers (4)