Results 1 to 3 of 3

Thread: Conventional Class Aggregation

  1. #1
    Join Date
    Feb 2007
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Conventional Class Aggregation

    Hi.

    I'm a self taught programmer coming from a procedural coding perspective (iso c) and I'm still developing my oop style skills.

    I wonder, generally speaking, if I have a .ui derived class (qdesigner), should I use that class as the aggregate for other (non .ui) component (related) classes, or would practical convention consider otherwise?

    Let me generalize this question... conventionally, is there a structured approach to determining how related classes might be aggregated "artistically"?


    thanks,
    travlr
    Last edited by travlr; 16th February 2007 at 06:23.

  2. #2
    Join Date
    May 2006
    Location
    Germany
    Posts
    108
    Thanks
    2
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Conventional Class Aggregation

    Aggregation can be best described as an "IS-PART-OF"-relation. That is a relation which does not apply to classes derived from .ui-generated classes, as those .ui-generated classes are not a part of your dialog, but a simple parent for inheritance.

    A good example for aggregation would be a car with an engine and tires:

    Qt Code:
    1. // engine is-part-of a car
    2. class Engine
    3. {
    4. };
    5.  
    6. // tire is-part-of a car
    7. class Tire
    8. {
    9. };
    10.  
    11. // a car is build from tires and an engine
    12. class Car
    13. {
    14. private:
    15. Engine m_engine;
    16. Tire* m_tires[4];
    17. };
    18.  
    19. // and now inheritance:
    20. // a Volkswagen is-a car
    21. class Volkswagen : public Car
    22. {
    23. };
    To copy to clipboard, switch view to plain text mode 

    So, the basic difference between aggregation and inheritance boils down to:
    1) Inheritance means you inherit something from one class to another (IS-KIND-OF or IS-A relationship)
    2) Aggregation combines several simple parts to construct a more complex object (IS-PART-OF relationship)

  3. #3
    Join Date
    Feb 2007
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Conventional Class Aggregation

    Quote Originally Posted by Methedrine View Post
    Aggregation can be best described as...
    Thank you Methedrine.

    Simply reminding me again of the IS-A, IS-PART-OF thought process, along with the "option" having the related classes in a single source file, helped me to better structure my code.

    As with all good instruction, your brief example demonstration was very illustrative.

    -travlr

Similar Threads

  1. ("Dynamic") Class in DLL
    By durbrak in forum Qt Programming
    Replies: 5
    Last Post: 29th January 2007, 15:43
  2. How to pass a QString to another class ?
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 9th December 2006, 21:16
  3. Replies: 2
    Last Post: 4th May 2006, 20:17
  4. How to propagate from one class to another
    By mahe2310 in forum Qt Programming
    Replies: 15
    Last Post: 20th March 2006, 02:27
  5. Replies: 5
    Last Post: 15th March 2006, 08:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.