Who owns the associated class in this uml diagram? - uml

Sorry for this newb question, i'm new to UML.
The diagram for a system is this one:
From what I know of UML, none of the classes in this diagram can own instances of the associated class as there's no aggregate relationship with it.
Does this mean in an implementation of the system in Java, based on the diagram, an outside class has to own instances of the associated class?
Sorry if the answer is obvious. I've spent hours scratching my head over it.

First off, terminology. #Daniel is right, you don't have an association class. However, I don't think you mean Association Class:
Does this mean in an implementation of the system in Java, based on the diagram, an outside class has to own instances of the associated class?
If I understand correctly that's the nub of your question. In implementation terms, which class(es) have a member variable containing a list of references to instances of Associated Class?
Again - if I understand right - your question stems from the following logic:
In UML, "ownership" is commonly described as a quality of Aggregation (or Composition) relationships.
The relationship between Aggregated/Composite PART Class and Associated Class is a simple binary association - not Aggregate/Composite.
Therefore the "ownership" property doesn't apply
Therefore who owns the list of references to Associated Class instances?
If that's right then the issue is with the specific meaning of "ownership". Whilst not tightly defined in UML, "ownership" typically means responsibility for managing full lifecycle.
I think you're interpreting it more generally: that if an association isn't aggregate, then the participating classes can't hold references to each other.
That's not the case. It's perfectly reasonable for Aggregated/Composite PART Class to hold a reference (or list of references) to instances of Associated Class. The inverse is equally valid. In some cases both are valid (with the attendant need to maintain consistency).
So in summary: is it necessary for an outside class to own the instances of Associated Class? No. It's perfectly valid for either or both ends of a binary association to manage instances of the relationship.
hth and apologies if I misunderstood your question.
PS: a final observation: be very careful about what you mean when using Aggregation. It's notoriously imprecise in the UML spec. Composition has a more rigorous definition, and you can cover 99% plus of all modelling scenarios using Composition and plain Binary Associations. About the only place Aggregation has a well-defined meaning not completely covered by the other two is denoting when recursive relationships must be acyclic.

UML does not specify the full behaviour of a system. So what do you mean, when you say an object owns another object? Also instances AssociatedClass could be root objects that are not owned by any other object.

The diagram you provided doesn't really contain an association class. The class you named 'associated class' is just a normal class. It also isn't owned by anything (that we see in the diagram).
If what you had in mind was association class, then take a look at example diagram with association class:
In this example, the MilleageCredit is an association class. So for each distinct combination of Fligh-FrequentFlyer there is one MilleageCredit.
As for ownership, since the Association class represents a relation between 2 associated objects, it gets deleted when
the association is cleared
either or both of associated objects are deleted
So if you delete either the Flight or FrequentFlyer the MilleageCredit will be gone too.
Also if you unlink Flight from FrequentFlyer again the MilleageCredit will be delete.
There's plenty of good UML docs online, for example UML basics: The class diagram
Hope this helps, otherwise please provide more info in the question.

Related

Class diagram - confused about aggregation [duplicate]

Here I am, with another question about aggregation and association. I wanted to learn some basics of UML, so I started reading "UML distilled" by Martin Fowler. I read both chapters about classes, and there is one thing that I can't fully grasp I think, and that is aggregation vs association. In the book there is this quote:
In the pre-UML days, people were usually rather vague on what was aggregation and what was
association. Whether vague or not, they were always inconsistent with everyone else. As a result,
many modelers think that aggregation is important, although for different reasons. So the UML
included aggregation (Figure 5.3) but with hardly any semantics. As Jim Rumbaugh says, "Think of it
as a modeling placebo" [Rumbaugh, UML Reference].
As I understand from this quote and topics that I read on Stack Overflow it doesn't matter which one of those two relations I use, they mean basically the same, or is there any situation where the usage of aggregation instead of association would be justified and/or I could not change one to the other without changing the "meaning" of a class diagram?
I am asking this, because this book is from 2003 and some things could have changed during those few years.
Maybe this can help you, but i don't think you will find the perfect explanation:
The difference is one of implication. Aggregation denotes whole/part
relationships whereas associations do not. However, there is not
likely to be much difference in the way that the two relationships are
implemented. That is, it would be very difficult to look at the code
and determine whether a particular relationship ought to be
aggregation or association. For this reason, it is pretty safe to
ignore the aggregation relationship altogether. [Robert C. Martin | UML]
And an example for each situation:
a) Association is a relationship where all object have their own
lifecycle and there is no owner. Let’s take an example of Teacher and
Student. Multiple students can associate with a single teacher and
single student can associate with multiple teachers, but there is no
ownership between the objects and both have their own lifecycle. Both
can create and delete independently.
b) Aggregation is a specialized form of Association where all object have their own lifecycle but there is ownership and child
object can not belong to another parent object. Let’s take an example
of Department and teacher. A single teacher can not belong to
multiple departments, but if we delete the department, the teacher object
will not be destroyed. We can think about “has-a” relationship.[Maesh | GeeksWithBlogs]
Rumbaugh's statement is the most telling and Uncle Bob's good advice. As I've said elsewhere, Aggregation is semantically so weak as to offer nothing practically beneficial. It only has one valid corner case (acyclicity of recursive relationships) however few people know and understand that. So you end up having to point out in comments anyway.
I just don't use it. And have never felt any loss. Stick with simple binary associations and focus on what really matters - getting the cardinality and naming right. You'll get far more from that than trying to decide the undecidable association vs. aggregation.
hth.
I tend to use Aggregation to show a relation that is the same as a Composition with one big distinction: the containing class is NOT responsible for the life-cycle of the contained object. Typically, a (non-null) pointer or reference to the object-to-be-contained is passed to the containing class's constructor. The containing object, for the duration of its life-cycle, depends upon the contained object existing. The containing object cannot do its job (fully) without the contained object. This is my interpretation of the "Part/Whole" relationship implied by Aggregation.
This term often gets confused.
Aggregation and composition are some of the types of association. There is
hardly a difference between aggregations and associations during
implementation, and many will skip aggregation relations altogether in
their diagrams with association relation.
You can get the idea from this analogy.
Class:A(person) and Class:B(car) has association relation, if
Class:A has a Class:B declaration, and also Class:B(car) object is not essential to create a Class:A(person) object.
Class:A(car) and Class:B(tyre) has aggregation relation, if
Class:A has a Class:B declaration, and also Class:B(tyre) object is essential to create a Class:A(car) object.
Cheers!
In UML aggregation is under-defined and since they haven't got any clearly defined semantic.
A valid use-case of an aggregation is the encapsulation of a several classes, as stated in "Domain Driven Design" by Eric Evans.
E.g. a car has four wheels.
You might want to calculate the total amount of meters each wheel has driven, for each car.
This calculation is done by the car-entity, since it knows which wheels it has and you don't care which wheels belong to which car.
The car is the aggregation-root for all it's parts, like wheels, and you can't access the parts of a car from outside the aggregation, just the root.
So basically an aggregation encapsulates a set of classes which belong to each other.
They do not mean the same! I can put it in this way:
Association relationship: A class references another class. Actually it shows that a class is related to another class but they
don't necessarily have attributes to show this relationship... e.g
'Teacher' and 'Student' classes, although 'Teacher' class has no
attribute that refer to students, but we do know that in reality a
teacher do have students... And also 'School' class has 'teachers' and
'students' properties that now make those two classes related to each
other.
Aggregation relationship: A class contains another class. But if the container(ClassRoom) is destroyed, the contained(Chair) is not.
Actually the ClassRoom owns the Chair. Aggregation is a more stronger
relationship than the Association relationship.
Here is also a tutorial about it and the whole UML2.0 which explains everything easy and simple, you may find it useful: https://github.com/imalitavakoli/learn-uml2
TIP: Also let me mention that because the Association relationship exists between classes most of the times, we sometimes don't draw it to prevent unnecessary complexity.
Implementation wise there is not much of a difference but conceptually there is big difference: aggregations are used to express a hierarchy. When you work with a hierarchy of components there are certain type of operations you need to have in the root interface:
find subcomponents in the hierarchy
add/remove subcomponents to/from the hierarchy
change common attributes of all components
traverse the hierarchy recursively (Visitor pattern)
reconfigure the hierarchy and the links (associations) between the components
Most of these operations are not needed when dealing with associations.
To add, I would just suggest to download the UML specification from the OMG site: best reference and see p 110.
None indicates that the property has no aggregation semantics.
Shared indicates that the property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.
Composite indicates that the property is aggregated compositely, i.e., the composite object has responsibility for
the existence and storage of the composed objects (see the definition of parts in 11.2.3).

UML class diagram Aggregation vs. Association [duplicate]

Here I am, with another question about aggregation and association. I wanted to learn some basics of UML, so I started reading "UML distilled" by Martin Fowler. I read both chapters about classes, and there is one thing that I can't fully grasp I think, and that is aggregation vs association. In the book there is this quote:
In the pre-UML days, people were usually rather vague on what was aggregation and what was
association. Whether vague or not, they were always inconsistent with everyone else. As a result,
many modelers think that aggregation is important, although for different reasons. So the UML
included aggregation (Figure 5.3) but with hardly any semantics. As Jim Rumbaugh says, "Think of it
as a modeling placebo" [Rumbaugh, UML Reference].
As I understand from this quote and topics that I read on Stack Overflow it doesn't matter which one of those two relations I use, they mean basically the same, or is there any situation where the usage of aggregation instead of association would be justified and/or I could not change one to the other without changing the "meaning" of a class diagram?
I am asking this, because this book is from 2003 and some things could have changed during those few years.
Maybe this can help you, but i don't think you will find the perfect explanation:
The difference is one of implication. Aggregation denotes whole/part
relationships whereas associations do not. However, there is not
likely to be much difference in the way that the two relationships are
implemented. That is, it would be very difficult to look at the code
and determine whether a particular relationship ought to be
aggregation or association. For this reason, it is pretty safe to
ignore the aggregation relationship altogether. [Robert C. Martin | UML]
And an example for each situation:
a) Association is a relationship where all object have their own
lifecycle and there is no owner. Let’s take an example of Teacher and
Student. Multiple students can associate with a single teacher and
single student can associate with multiple teachers, but there is no
ownership between the objects and both have their own lifecycle. Both
can create and delete independently.
b) Aggregation is a specialized form of Association where all object have their own lifecycle but there is ownership and child
object can not belong to another parent object. Let’s take an example
of Department and teacher. A single teacher can not belong to
multiple departments, but if we delete the department, the teacher object
will not be destroyed. We can think about “has-a” relationship.[Maesh | GeeksWithBlogs]
Rumbaugh's statement is the most telling and Uncle Bob's good advice. As I've said elsewhere, Aggregation is semantically so weak as to offer nothing practically beneficial. It only has one valid corner case (acyclicity of recursive relationships) however few people know and understand that. So you end up having to point out in comments anyway.
I just don't use it. And have never felt any loss. Stick with simple binary associations and focus on what really matters - getting the cardinality and naming right. You'll get far more from that than trying to decide the undecidable association vs. aggregation.
hth.
I tend to use Aggregation to show a relation that is the same as a Composition with one big distinction: the containing class is NOT responsible for the life-cycle of the contained object. Typically, a (non-null) pointer or reference to the object-to-be-contained is passed to the containing class's constructor. The containing object, for the duration of its life-cycle, depends upon the contained object existing. The containing object cannot do its job (fully) without the contained object. This is my interpretation of the "Part/Whole" relationship implied by Aggregation.
This term often gets confused.
Aggregation and composition are some of the types of association. There is
hardly a difference between aggregations and associations during
implementation, and many will skip aggregation relations altogether in
their diagrams with association relation.
You can get the idea from this analogy.
Class:A(person) and Class:B(car) has association relation, if
Class:A has a Class:B declaration, and also Class:B(car) object is not essential to create a Class:A(person) object.
Class:A(car) and Class:B(tyre) has aggregation relation, if
Class:A has a Class:B declaration, and also Class:B(tyre) object is essential to create a Class:A(car) object.
Cheers!
In UML aggregation is under-defined and since they haven't got any clearly defined semantic.
A valid use-case of an aggregation is the encapsulation of a several classes, as stated in "Domain Driven Design" by Eric Evans.
E.g. a car has four wheels.
You might want to calculate the total amount of meters each wheel has driven, for each car.
This calculation is done by the car-entity, since it knows which wheels it has and you don't care which wheels belong to which car.
The car is the aggregation-root for all it's parts, like wheels, and you can't access the parts of a car from outside the aggregation, just the root.
So basically an aggregation encapsulates a set of classes which belong to each other.
They do not mean the same! I can put it in this way:
Association relationship: A class references another class. Actually it shows that a class is related to another class but they
don't necessarily have attributes to show this relationship... e.g
'Teacher' and 'Student' classes, although 'Teacher' class has no
attribute that refer to students, but we do know that in reality a
teacher do have students... And also 'School' class has 'teachers' and
'students' properties that now make those two classes related to each
other.
Aggregation relationship: A class contains another class. But if the container(ClassRoom) is destroyed, the contained(Chair) is not.
Actually the ClassRoom owns the Chair. Aggregation is a more stronger
relationship than the Association relationship.
Here is also a tutorial about it and the whole UML2.0 which explains everything easy and simple, you may find it useful: https://github.com/imalitavakoli/learn-uml2
TIP: Also let me mention that because the Association relationship exists between classes most of the times, we sometimes don't draw it to prevent unnecessary complexity.
Implementation wise there is not much of a difference but conceptually there is big difference: aggregations are used to express a hierarchy. When you work with a hierarchy of components there are certain type of operations you need to have in the root interface:
find subcomponents in the hierarchy
add/remove subcomponents to/from the hierarchy
change common attributes of all components
traverse the hierarchy recursively (Visitor pattern)
reconfigure the hierarchy and the links (associations) between the components
Most of these operations are not needed when dealing with associations.
To add, I would just suggest to download the UML specification from the OMG site: best reference and see p 110.
None indicates that the property has no aggregation semantics.
Shared indicates that the property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.
Composite indicates that the property is aggregated compositely, i.e., the composite object has responsibility for
the existence and storage of the composed objects (see the definition of parts in 11.2.3).

UML - association or aggregation (simple code snippets)

I drives me crazy how many books contradicts themselves.
Class A {} class B {void UseA(A a)} //some say this is an association,
no reference is held but communication is possible
Class A {} class B {A a;} //some say this is
aggregration, a reference is held
But many say that holding a reference is still just an association and for aggregation they use a list - IMHO this is the same, it it still a reference.
I am very confused, I would like to understand the problem.
E.g. here: http://aviadezra.blogspot.cz/2009/05/uml-association-aggregation-composition.html - what is the difference between Strong Association and Aggregation, in both cases the author uses a field to store the reference..
Another example:
This is said to be Association:
And this is said to be Aggregration:
public class Professor {
// ...
}
public class Department {
private List<Professor> professorList;
// ..
}
Again, what is the difference? It is a reference in both cases
This question has been, and will be, asked many times in many different variants, because many people, including many high-profile developers, are confused about the meaning of these terms, which have been defined in the UML. Since the question has been asked many times, it has also been answered many times. See, e.g. this answer. I'll try to summarize the UML definitions.
An association between two classes is not established via a method parameter, but rather via reference properties (class attributes), the range/type of which are the associated classes. If the type of a method parameter is a class, this does not establish an association, but a dependency relationship.
It's essential to understand the logical concept of associations first, before looking at how they are coded. An association between object types classifies relationships between objects of those types. For instance, the association Committee-has-ClubMember-as-chair, which is visualized as a connection line in the class diagram shown below, may classify the relationships FinanceCommittee-has-PeterMiller-as-chair, RecruitmentCommittee-has-SusanSmith-as-chair and AdvisoryCommittee-has-SarahAnderson-as-chair, where the objects PeterMiller, SusanSmith and SarahAnderson are of type ClubMember, and the objects FinanceCommittee, RecruitmentCommittee and AdvisoryCommittee are of type Committee.
An association is always encoded by means of reference properties, the range/type of which is the associated class. For instance, like so
class Committee { ClubMember chair; String name;}
In the UML, aggregation and composition are defined as special forms of associations with the intended meaning of classifying part-whole-relationships. In the case of aggregation, as opposed to composition, the parts of a whole can be shared with other wholes. This is illustrated in the following example of an aggregation, where a course can belong to many degree programs.
The defining characteristic of a composition is to have exclusive (or non-shareable) parts. A composition may come with a life-cycle dependency between the whole and its parts implying that when a whole is destroyed, all of its parts are destroyed with it. However, this only applies to some cases of composition, and not to others, and it is therefore not a defining characteristic. An example of a composition where the parts (components) can be detached from the whole (composite) and therefore survive its destruction, is the following:
See Superstructures 2.1.1:
An association may represent a composite aggregation (i.e., a whole/part relationship). Only binary associations can be aggregations. Composite aggregation is a strong form of aggregation that requires a part instance be included in at most one composite at a time. If a composite is deleted, all of its parts are normally deleted with it. Note that a part can (where allowed) be removed from a composite before the composite is deleted, and thus not be deleted as part of the composite. Compositions may be linked in a directed acyclic graph with transitive deletion characteristics; that is, deleting an element in one part of the graph will also result in the deletion of all elements of the subgraph below that element. Composition is represented by the isComposite attribute on the part end of the association being set to true.
Navigability means instances participating in links at runtime (instances of an association) can be accessed efficiently from instances participating in links at the other ends of the association. The precise mechanism by which such access is achieved is implementation specific. If an end is not navigable, access from the other ends may or may not be possible, and if it is, it might not be efficient. Note that tools operating on UML models are not prevented from navigating associations from non-navigable ends.
Your above examples are on different abstraction levels. Department/Course are concrete coding classes while Department/Professor are at some abstract business level. Though there is no good source (I know) explaining this fact, composition and aggregation are concepts you will use only on business level and almost never at coding level (exception below). When you are at code level you live much better with Association having role names on both sides. Roles themselves are a different(/redundant!) rendering of properties of a class that refer to the opposite class.
Aggregation as a strong binding between classes is used e.g. in database modeling. Here you can delete a master only if the aggregates have all been deleted previously (or vice vera: deleting the master will force deletion of the aggregates). The aggregate can not live on its own. The composition as in your example is (from my POV) a silly construct as it pretends to be some week aggregation. But that's simply nonsense. Then use an association. Only on a business level you can try to model (e.g.) machine parts as composite. On a concrete level a composition is a useless concept.
tl;dr;
If there is a relation between classes show it as simple association. Adding details like roles will aid when discussing domain details. Use of composition/aggregation is encouraged only when modeling on business level and dis-encouraged on code level.
I've written an article about the differences between UML Association vs Aggregation vs Composition based on the actual UML specification rather then interpretations of book authors.
The primary conclusion being that
In short, the Composition is a type of Association with real constraints and impact on development, whereas the Aggregation is purely a functional indication of the nature of the Association with no technical impact.
Navigability is a completely different property and independent of the AggregationKind.
For one thing, UML is a rich language, meaning there is more than one way to describe the same thing. That's one reason you find different ways described in different books (and conflicting answers on SO).
But a key issue is the huge disconnect between UML and source code. How a specific source code construct is represented in UML, and vice versa, is not part of the UML specification at all. To my knowledge, only one language (Java) has an official UML profile, and that's out of date.
So the representation of specific source-language constructs are left to the tool vendors, and therefore differ. If you intend to generate code from your model, you must follow the vendor's conventions. If, conversely, you wish to generate a model from existing source code, you get a model based on those same conventions. But if you transfer that model to a different tool (which is difficult at the best of times) and generate code out of that, you won't end up with the same code.
In language-and-tool-agnostic mode, my take on which relationships to use in which situations can be found here. One point there worth repeating is that I don't use undirected associations in source-code models, precisely because they have no obvious counterpart in actual code. If in the code class A has a reference to class B, and B also has one to A, then I draw two relationships instead.

Semantic relationship in UML

I found a definition for association in UML as below.
An "association" in UML is defined as a kind of relationship between
classes,which represents the semantic relationship between two or more classes that
involves connections (links) among their instances .
I am not clear what is semantic relationship. Can anyone explain it with example with comparing it with non semantic relationship?
Associations in plain text
An association is a semantic relationship. The UML clause means that there is a structural relationship between instances of the associated classes independently of any specific implementation. "Semantic" underlines that the relationship is between the instances themselves, and not just "accidentally" for an operation:
Use associations primarily where there are structural relationships among objects. Do not use them to show transient relationships such as parameters or local variables of procedures.- Booch, Rumbaugh & Jacobson in Unified Modeling Language User Guide, 2nd edition
More arguments
What is "semantic"?
The term "semantic" is borrowed from linguistics and refers to the meanings behind the words. Linguists and map words (e.g. "Car", "Driver") to their meaning (e.g. a real car, a real person), and analyze the relation between words with a view of this mapping:
So, applying this to UML (modelling language) if you'd have the classes Car and Driver, you CAN model the semantic relationship as an association between the two classes.
What is not semantic?
Not all relationships are of semantic nature. You can have dependencies, which can express a technical relationship:
a transient relationship during an operation: with a factory pattern for example, a DriverFactory would «create» a Driver instance. Both instances the factory and the driver are related only at the exact moment of the creation operation. But the two instances are completely independent the nanosecond after.The same applies if the implementation of an operation needs to create a local instance of another class. Both classes are not associated, since we could imagine another implementation that works without such an instance.
a structural dependency: Maybe an operation require some other classes as parameter. Since the parameters themselves are transient, there is no association. But nevertheless, teh class needs to know about the other class.
For the records, I'm grateful to this public domain contributor for the nice car and driver and to 18f for advice on inclusive communication.
The subject of Semantics is sense. If one thing has something that is connected by sense to another thing, it is the semantic relationship. That definition is terribly wide. And, applied to UML relationship, incorrect. It is incorrect for two reasons.
First, UML covers not only Class-Instance languages, such as Java or C++, but pure object languages with heredity created by Prototypes as well. And this second variant is not covered by your definition at all.
Second, in UML you can have class A connected to class B through some complex AssociationClass, that is shown by a box with arrows, not arrow only. And it still will be named an association and it IS a semantic relationship, too. But a the semantic relationship goes from A to B through two classes, it is still a semantic relationship, but it is not an association in UML.
If you are trying to be deep in subject, better read the UML documentation: "An Association classifies a set of tuples representing links between typed instances." (UML 2.5, pharagraph 11.5.1). Notice: ANY link between two instances can be shown as an association. Maybe the book you are reading is wholely not so bad, but in the very place that you have cited the author merely tries to use pretty words not understanding their meaning and not even trying to be understandable to readers and to be CORRECT.
A model says something about the things being modeled. This is its semantics. Almost all elements of UML have semantics, defined in the sections titled "semantics". One exception is the comment. Adding a comment to a model doesn't influence its meaning.
Then why does the UML say this explicitely about associations? The reason is, that an association may or may not say something about the structure. If it doesn't, it is purely semantic.
For example it could tell us, that a Car can have at most one Driver. It doesn't necessarily mean that the car has an attribute of type Driver.
If we want to model that the two associated classes own attributes typed by the other end of the association, the notation will show this by small dots on its ends. Many people are not familiar with this notation and interpret associations without a dot in the same way. However, without the dots attributes are owned by the association itself and the structure of the classes is not influenced.
By the way, a class being the type of a parameter of an operation or having a dependency also means a semantic relationship.

UML aggregation vs association

Here I am, with another question about aggregation and association. I wanted to learn some basics of UML, so I started reading "UML distilled" by Martin Fowler. I read both chapters about classes, and there is one thing that I can't fully grasp I think, and that is aggregation vs association. In the book there is this quote:
In the pre-UML days, people were usually rather vague on what was aggregation and what was
association. Whether vague or not, they were always inconsistent with everyone else. As a result,
many modelers think that aggregation is important, although for different reasons. So the UML
included aggregation (Figure 5.3) but with hardly any semantics. As Jim Rumbaugh says, "Think of it
as a modeling placebo" [Rumbaugh, UML Reference].
As I understand from this quote and topics that I read on Stack Overflow it doesn't matter which one of those two relations I use, they mean basically the same, or is there any situation where the usage of aggregation instead of association would be justified and/or I could not change one to the other without changing the "meaning" of a class diagram?
I am asking this, because this book is from 2003 and some things could have changed during those few years.
Maybe this can help you, but i don't think you will find the perfect explanation:
The difference is one of implication. Aggregation denotes whole/part
relationships whereas associations do not. However, there is not
likely to be much difference in the way that the two relationships are
implemented. That is, it would be very difficult to look at the code
and determine whether a particular relationship ought to be
aggregation or association. For this reason, it is pretty safe to
ignore the aggregation relationship altogether. [Robert C. Martin | UML]
And an example for each situation:
a) Association is a relationship where all object have their own
lifecycle and there is no owner. Let’s take an example of Teacher and
Student. Multiple students can associate with a single teacher and
single student can associate with multiple teachers, but there is no
ownership between the objects and both have their own lifecycle. Both
can create and delete independently.
b) Aggregation is a specialized form of Association where all object have their own lifecycle but there is ownership and child
object can not belong to another parent object. Let’s take an example
of Department and teacher. A single teacher can not belong to
multiple departments, but if we delete the department, the teacher object
will not be destroyed. We can think about “has-a” relationship.[Maesh | GeeksWithBlogs]
Rumbaugh's statement is the most telling and Uncle Bob's good advice. As I've said elsewhere, Aggregation is semantically so weak as to offer nothing practically beneficial. It only has one valid corner case (acyclicity of recursive relationships) however few people know and understand that. So you end up having to point out in comments anyway.
I just don't use it. And have never felt any loss. Stick with simple binary associations and focus on what really matters - getting the cardinality and naming right. You'll get far more from that than trying to decide the undecidable association vs. aggregation.
hth.
I tend to use Aggregation to show a relation that is the same as a Composition with one big distinction: the containing class is NOT responsible for the life-cycle of the contained object. Typically, a (non-null) pointer or reference to the object-to-be-contained is passed to the containing class's constructor. The containing object, for the duration of its life-cycle, depends upon the contained object existing. The containing object cannot do its job (fully) without the contained object. This is my interpretation of the "Part/Whole" relationship implied by Aggregation.
This term often gets confused.
Aggregation and composition are some of the types of association. There is
hardly a difference between aggregations and associations during
implementation, and many will skip aggregation relations altogether in
their diagrams with association relation.
You can get the idea from this analogy.
Class:A(person) and Class:B(car) has association relation, if
Class:A has a Class:B declaration, and also Class:B(car) object is not essential to create a Class:A(person) object.
Class:A(car) and Class:B(tyre) has aggregation relation, if
Class:A has a Class:B declaration, and also Class:B(tyre) object is essential to create a Class:A(car) object.
Cheers!
In UML aggregation is under-defined and since they haven't got any clearly defined semantic.
A valid use-case of an aggregation is the encapsulation of a several classes, as stated in "Domain Driven Design" by Eric Evans.
E.g. a car has four wheels.
You might want to calculate the total amount of meters each wheel has driven, for each car.
This calculation is done by the car-entity, since it knows which wheels it has and you don't care which wheels belong to which car.
The car is the aggregation-root for all it's parts, like wheels, and you can't access the parts of a car from outside the aggregation, just the root.
So basically an aggregation encapsulates a set of classes which belong to each other.
They do not mean the same! I can put it in this way:
Association relationship: A class references another class. Actually it shows that a class is related to another class but they
don't necessarily have attributes to show this relationship... e.g
'Teacher' and 'Student' classes, although 'Teacher' class has no
attribute that refer to students, but we do know that in reality a
teacher do have students... And also 'School' class has 'teachers' and
'students' properties that now make those two classes related to each
other.
Aggregation relationship: A class contains another class. But if the container(ClassRoom) is destroyed, the contained(Chair) is not.
Actually the ClassRoom owns the Chair. Aggregation is a more stronger
relationship than the Association relationship.
Here is also a tutorial about it and the whole UML2.0 which explains everything easy and simple, you may find it useful: https://github.com/imalitavakoli/learn-uml2
TIP: Also let me mention that because the Association relationship exists between classes most of the times, we sometimes don't draw it to prevent unnecessary complexity.
Implementation wise there is not much of a difference but conceptually there is big difference: aggregations are used to express a hierarchy. When you work with a hierarchy of components there are certain type of operations you need to have in the root interface:
find subcomponents in the hierarchy
add/remove subcomponents to/from the hierarchy
change common attributes of all components
traverse the hierarchy recursively (Visitor pattern)
reconfigure the hierarchy and the links (associations) between the components
Most of these operations are not needed when dealing with associations.
To add, I would just suggest to download the UML specification from the OMG site: best reference and see p 110.
None indicates that the property has no aggregation semantics.
Shared indicates that the property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.
Composite indicates that the property is aggregated compositely, i.e., the composite object has responsibility for
the existence and storage of the composed objects (see the definition of parts in 11.2.3).

Resources