469,346 Members | 6,539 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,346 developers. It's quick & easy.

Design problem with List containing class inheritance

Hi,

i am having trouble solving a design problem i'm sure is common,
and wanted some help.

for berevity i'll skim the problem to a smaller example.

I have a design where a base class is called SEGMENT and inheriting from it is FLOW. in SEGMENT i keep a List Of BaseObjects, BaseObject is a Class which FlowObject Inherits From.

the relationship should be:
Segment<---Flow
BaseObject<---FlowObject
and Segment Has A List Of BaseObject, Flow Has A List Of FlowObject,

i though i would keep a member in segment of List<BaseObject>
and would use in Flow the same member to keep the inherited classes FlowObjects as well.

Keeping the list in the base is helpful to me because there are operations that happen on all baseobjects/flowobjects ( such as save to disk / print, etc. )

but going to code testing, i descovered that some classes will need to use the List of FlowObjects outside a Flow, and that would require a casting from the base to the child for each class which is O(n) time and is wasteful.

this seems like a common issue. -- containment of 1:n classes in another class, both with their own inheretance. Any ideas?

Thanks,
Koren.
May 29 '08 #1
0 1294

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

18 posts views Thread by George Sakkis | last post: by
5 posts views Thread by Andrew Ward | last post: by
31 posts views Thread by grahamo | last post: by
reply views Thread by JKJ | last post: by
14 posts views Thread by Mark O'Flynn | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.