Re: Design Problem Aggregation
From: John Carson (donaldquixote_at_datafast.net.au)
Date: 05/10/04
- Next message: bartek: "Re: inheritance - problem with identyfing object"
- Previous message: Juergen Heinzl: "Re: question about object destruction"
- In reply to: Merlin: "Design Problem Aggregation"
- Next in thread: Merlin: "Re: Design Problem Aggregation"
- Reply: Merlin: "Re: Design Problem Aggregation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 10 May 2004 10:05:30 +1000
"Merlin" <merlin2769@hotmail.com> wrote in message
news:12235816.0405091453.5083bb2e@posting.google.com
> Hi
>
> Imagine the following classes (A class diagram will help)
>
> BASE, A, B, C, D, E, F, G.
>
>
> A, B, C, D, G inherit from BASE.
>
> E, F inherit from D.
>
> Class E has a member (aggregation by value) of type A.
> Class F has a member (aggregation by value) of type B.
>
>
> Class G has a member that is container that can accept objects of type
> D. As D is the base class of E and F we can add to the container
> objects of type E or F. I have made the container type safe in this
> way.
>
> I wanted G to be a collection of objects of type A or B but never C so
> I introduced an abstract class D and made the container of that type
> so it would only accept objects of base type D. However, although this
> looks ok, I am not happy with the extra work it has created.
> As I need to access the interface to A and B, I need to repeat all
> that interface in E and F. A and B have many member functions and I
> dont want to rewrite all that interface in E and F and delegate the
> calls to the aggregate.
>
> The solution where I provide a member function in classes E and F to
> return the aggregate seems wrong as its exposing a private data
> member.
I would be happy to do something even simpler: make the A and B objects
contained in E and F (respectively) public members; this doesn't involve any
more exposure than if you had just declared
A a;
B b;
> How can I change my design to make it better and flexible?
How about ditching E and F and making A and B inherit from D (which in turn
inherits from Base)?
-- John Carson 1. To reply to email address, remove donald 2. Don't reply to email address (post here instead)
- Next message: bartek: "Re: inheritance - problem with identyfing object"
- Previous message: Juergen Heinzl: "Re: question about object destruction"
- In reply to: Merlin: "Design Problem Aggregation"
- Next in thread: Merlin: "Re: Design Problem Aggregation"
- Reply: Merlin: "Re: Design Problem Aggregation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|