I understand thats its just a logical principal however, here is my understanding of this. Some people used the "car" example for describing Composition, but wheels and engine can be removed and used elsewhere so i used the human body as an alternative as they cant exist without certain organs lol.
here goes,
COMPOSITION:
Composition simply refers to an object that is made up of smaller more simple parts. A Human Body is composed of many organs (we will refer to them as parts for this example) a brain, heart and lungs lets say. We could have these as different objects, lets say we had a base class called “Body” these objects are part of the body, therefore we can say that this relationship carry’s the “PART OF” type as such:
Object 1 = Brain
Object 2 = Heart
Object 3 = Lungs
a heart is part of a body, a brain and the lungs are also critical to its existence and without them the body would cease to function. Together they form the finished article … they work together to form the finished piece …. The Body object. This is a simple way for now to describe Composition. If one goes then the whole object is no good, its destroyed.
AGGREGATION:
Aggregation tends to explain how members of a class can contain delegate some or all of its properties and methods to other classes or the same class, a type of relationship. For instance, as with the car example earlier, lets now do an example of a university. A university HAS A lecturer/ employee. If the university is destroyed then the employee still exists and can be put to use in another university, all is not lost, they can be moved around and interchanged.
am i on the correct tracks?
here goes,
COMPOSITION:
Composition simply refers to an object that is made up of smaller more simple parts. A Human Body is composed of many organs (we will refer to them as parts for this example) a brain, heart and lungs lets say. We could have these as different objects, lets say we had a base class called “Body” these objects are part of the body, therefore we can say that this relationship carry’s the “PART OF” type as such:
Object 1 = Brain
Object 2 = Heart
Object 3 = Lungs
a heart is part of a body, a brain and the lungs are also critical to its existence and without them the body would cease to function. Together they form the finished article … they work together to form the finished piece …. The Body object. This is a simple way for now to describe Composition. If one goes then the whole object is no good, its destroyed.
AGGREGATION:
Aggregation tends to explain how members of a class can contain delegate some or all of its properties and methods to other classes or the same class, a type of relationship. For instance, as with the car example earlier, lets now do an example of a university. A university HAS A lecturer/ employee. If the university is destroyed then the employee still exists and can be put to use in another university, all is not lost, they can be moved around and interchanged.
am i on the correct tracks?