Re: Design Problem Aggregation

From: Merlin (
Date: 05/11/04

Date: 11 May 2004 11:20:04 -0700


Thank you both for your suggestions. What has been suggested works
well if no
class sits between BASE and A or BASE and B.

In order to make things clear, discard the original classes and
consider the following scenario.

Imagine we have the following classes

BASE, A, B, C, D, E, F, G, H, I, and J (class diagram will help)

Classes A, D, F, G, J inherit from BASE.

Class B inherits from A

Class C inherits from B

Class E inherits from D

Classes H and I inherit from G

Class H has a member (aggregation by value) of type C.
Class I has a member (aggregation by value) of type E.

Class J has a member that is container that can accept objects of type
G. As G is the base class of H and I we can add to the container
objects of type H or I. I have made the container type safe in this

J is not a container, it has a member that is a container. My design
requires this. Also J does indeed inherit from BASE.

I wanted J to be a collection of objects of type C or E but never F or
even BASE so I introduced an abstract class G and made the container
of that type so it would only accept objects of base type G. However,
although this looks ok, I am not happy with the extra work it has

As I need to access the interface to C and E, I need to repeat all
that interface in H and I. C and E have many member functions and I
dont want to rewrite all that interface in H and I and delegate the
calls to the aggregate.

How can I change my design to make it better and flexible?

If I do what you suggested I will have multiple inheritance and cyclic
dependencies. What else can I do to get a type safe container? Should
I put member functions in G to return the objects C and E? Doesnt that
break encapsulation?

Thanks Again,