Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Design problem with List containing class inheritance

Question posted by: koren99 (Newbie) on May 29th, 2008 06:13 AM
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.
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Reply
Not the answer you were looking for? Post your question . . .
182,530 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Software Development Forum Contributors