Aggregation and Generalization
3 posts in topic
Flat View  Flat View

Posted By:   Pradeepkumar_Anandan
Posted On:   Monday, July 1, 2002 03:15 AM

As i had understood Agrregation mean a part whole relation ship between objects so when we say whole realtionship between ojects does it imply Generalization.

An example like:

A window is a part of Car is an aggreagate object.
Same Car class extending Window class is a generalization

So in this case it is both Aggregation and Generalization and so way are they related.


Re: Aggregation and Generalization

Posted By:   Anonymous  
Posted On:   Friday, August 30, 2002 01:34 AM

Actually the difference is a bit more blurred than the other answers might imply.

Aggregation and inheritance have quite a bit in common, the major thing being that they are both hierarchical.

The most important thing to remember when picking between the two comes down entirely to context - what makes sense for your model ? I can see that in some cases it would be entirely valid to model Car specialises Window, even though the every-day "common sense" approach would say it's an aggregation.

*THE* acid test for inheritance is that if A specialises B then it is an explicit part of the model that I could use an instance of A *anywhere* I could use an instance of *B* and whilst the behaviour might be different, it would still make sense. By that test, in most cases a Car cannot inherit from a Window.

However if you were a modern architect and were building a funky new building that embedded various unusual objects in its facade, some of which were acts that acted as windows then Car inherits from Window makes a lot of sense. See what I mean about context ?

Re: Aggregation and Generalization

Posted By:   Simon_Ablett  
Posted On:   Monday, July 1, 2002 05:09 AM

Aggregation and composition are containment relationships. For example, a car contains windows.

Generalization, in the form of 'public inheritance', implies an 'is a' relationship. So if car were to inherit from window what you would ostensibly be saying is that 'car is of type window' which is not true - well not in my version of reality ;-)

Hope that this clarifies things.

Re: Aggregation and Generalization

Posted By:   Gautam_Marwaha  
Posted On:   Monday, July 1, 2002 05:08 AM

Like you said, aggregation is whole-part relationship. It is more of a structural relationship.

Generalization on the other hand implies parent-child/inheritance where child is almost similar to the parent but may exhibit different behaviour by over-riding methods and provide some new ones.

Aggregation: Car-Windows looks ok

Generalization: Car class extending Window seems incorrect- there is hardly any similarity between the two. Car will never need to inherit any behaviour from Window. A Vehicle-Car may be a better example of generalization.
About | Sitemap | Contact