Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Originally posted by Michael Ernest:
I'm sure the term you intended is aggregation. Building a class by aggregation (sometimes also referred to as composition) simply means building a class by composing it from other classes, rather than from inheritance.
Component models rely heavily on composition, where the class that puts all things together is viewed as a container. In physical terms, one intuitively useful model is a Car. A Car can be defined as composed of several objects (parts), and it's behavior derived from the interaction of those parts to form the whole. Compare that to inheritance, where perhaps we derive behavior from a Transport interface or Vehicle parent class. The end result of the two approaches might be the same, from the perspective of its user, but the development of either type would naturally be quite different.
Hope This Helps
Originally posted by Rodney Woodruff:
Inheritance infers an "is a" relationship!!
For example: public class Dog extends Animal
In this example we would say a Dog "is a" Animal because of its relationship to Animal.
Aggregation infers a "has a" relationship!!
For example:
public class Dog extends Animal{
Paw leftPaw = new Paw();
Paw rightPaw = new Paw();
Paw backLeftPaw = new Paw();
Paw backRightPaw = new Paw();
}
In this example, we would say that a Dog has paws. Moreover, other animals, like tigers, bears, etc. also have paws.
So, aggregation refers to how objects are used to create other objects (i.e. composition).
Hope this helps.
Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
|