Re: Design Problem Aggregation

From: Merlin (merlin2769_at_hotmail.com)
Date: 05/10/04

  • Next message: Thomas Lutz: "Re: I need Information to print a barcode in VC++"
    Date: 10 May 2004 11:41:09 -0700
    
    

    Hi John

    Thanks for your suggestion. I like your first suggestion but making
    the members public makes me a bit uneasy. Your second suggestion 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
    way.

    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
    created.

    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?

    Many Thanks

    Merlin


  • Next message: Thomas Lutz: "Re: I need Information to print a barcode in VC++"

    Relevant Pages

    • Re: The meaning of set?
      ... The meaning of sets and set membership: ... A container is what has the ability to contain some of what is other ... Inclusion rule to a container is the requirement for being contained ... So a member of a set is what fulfils the requirements of inclusion into ...
      (sci.math)
    • Re: The meaning of set?
      ... The meaning of sets and set membership: ... A container is what has the ability to contain some of what is other ... Inclusion rule to a container is the requirement for being contained ... So a member of a set is what fulfils the requirements of inclusion into ...
      (sci.math)
    • Re: The meaning of set?
      ... The meaning of sets and set membership: ... A container is what has the ability to contain some of what is other ... Inclusion rule to a container is the requirement for being contained ... So a member of a set is what fulfils the requirements of inclusion into ...
      (sci.math)
    • Re: The meaning of set?
      ... The meaning of sets and set membership: ... A container is what has the ability to contain some of what is other ... Inclusion rule to a container is the requirement for being contained ... So a member of a set is what fulfils the requirements of inclusion into ...
      (sci.math)
    • The meaning of set?
      ... The meaning of sets and set membership: ... A container is what has the ability to contain some of what is other ... Inclusion rule to a container is the requirement for being contained ... So a member of a set is what fulfils the requirements of inclusion into ...
      (sci.math)