I'm looking for a some clarification I have with regards to the class diagram below: "Is it an aggregation or a composition? Explain why."
I'm in two minds about this answer. From what I understand initially the student 'has a' family, mother and father; therefore this is an example of composition because the concept of a mother or father cease to exist without the student (son,daughter) existing. However, if I look at it another way, if the student (child) [ceases to exist]/[never existed at all], there is still the possibility that two individual objects (here named Father and Mother) exist and would still contain the same attributes; which would be an example of aggregation.
Hopefully how I've tried to convey my line of thought makes sense. Can somebody please clear this up for me?
Thank you for your time.
Assuming you have correct usage of UML diagram, the answer is on the picture — it's aggregation, based on the arrows type. But let's find out. Also this article has the same explanation I as wrote, but in different words.
Let's go step-by-step with your statements.
the student 'has a' family, mother and father
Not quite correct: Mother “has” Family and Father “has” Family. And the Family “has” Student.
Let's look at an example from Wiki:
The diagram on top shows Composition between two classes: A Car has exactly one Carburetor, and a Carburetor is a part of one Car. Carburetors cannot exist as separate parts, detached from a specific car. The diagram on bottom shows Aggregation between two classes: A Pond has zero or more Ducks, and a Duck has at most one Pond (at a time). Duck can exist separately from a Pond, e.g. it can live near a lake.
According to this description to the illustration, the object to which arrow attached is the owner. But let's go to the next your statement.
because the concept of a mother or father cease to exist without the student
That's not quite correct as your diagram does not depict any “concepts”, UML diagrams show object properties and relationships between them. So if there is any “concept”, it should be stated outside of the diagram.
Let's assume that your diagram shows relationships from the real world: can Family exists without “being a part” of Mother or Father? No. Then, relationships between Mother, Father and Family is composition as Family by itself isn't used and does not exist.
if the student (child) [ceases to exist]/[never existed at all], there is still the possibility that two individual objects (here named Father and Mother) exist and would still contain the same attributes
Correct. But according to the diagram, they didn't have any relationships in the first place. So there is no need to question or prove their affection on each other. But you should be looking at relationships between Family and Student.
Can Student be a valid object and act by itself if it's not a part of a Family? According to the real world — yes, it's possible. Then, it's composition.
Important remark: I implied relations between these objects, taking rules from the real world, for example, that Family does not exist if it's not a part of some Father and Mother.
But in programming, where we use OO models and relations, we know that these models do not reflect the real world 1 to 1, so can object
Family be used if there are no Father and Mother objects in some program? Sure it can — depending on the purpose of the object. For example, it can be used to store statistical data, without any connections to concrete Father and Mother. That would make this relationship an aggregation. To avoid such questions, relationships between objects and their possibility to live on their own should be described explicitly, so the correct relationship type can be assumed.