I always thought that the UML aggregate is defined as a black (filled) diamond at the beginning of a path and no arrow head that the end:
|--------| |--------|
| :MyA |<>------| :MyB |
|--------| |--------|
Today I came across a notation like <>-----> (with an explicit arrow head on the right end). So I looked it up in the UML 2.4 specification and actually found references for both versions.
My favourite reference: "UML and Patterns" by Craig Larman only mentions the first version without the arrow. In the UML specification I found a notice about navigable ends, but I am not sure if this is related and if whats the difference?
Could someone explain this more thoroughly and give an example for the use of each version?
Any association end can be designated to be "navigable" with the help of a navigability arrow. However, UML's notion of "navigability" does not have a precise meaning and people confused it with the concept of an association end being owned by the class at the other end. This concept of association end ownership by a class means that the association end corresponds to a reference property of that class. This issue has only been clarified in last year's new UML version 2.5, which has introduced a new visual notation for association end ownership, a "dot" as in . This is most likely the intended meaning of what you came across, namely , and what it really means is the following reference property:
For more explanation see this tutorial.
Additional answer to the comment: If your class model specifies the ownership of all association ends, and your class diagram displays them, and there is no ownership dot (nor a navigability arrow), as in , then, according to UML 2.5, the association end is "owned" by the association itself. Since we do neither have an ownership dot at the MyA end, both ends are "owned" by the composite association. In terms of the code to write/generate, this would mean that the composite association is not implemented by means of reference properties in either MyA or MyB, but has to be implemented with the help of a separate class, say "MyA-has-MyB", which has two reference properties for referencing both the aggregate and the component of any composition link, as in the following class rectangle:
One arrow means the association is navigable this way. No arrows means the association is navigable BOTH ways. Two arrows are omitted.
It could be a problem, because two ends with undefined navigability look out the same way, but it is the standard.
You can read more thoroughly about associations/navigability/aggregations in this my answer https://stackoverflow.com/a/21478862/715269
Direction implies a client/server or master/slave relationship. In the case of aggregation, the usual situation is the programmer uses the aggregate to find the sub-components for that object (e.g., use the car to find the car parts). Directionality towards the part class makes this relationship explicit, though in most cases it is redundant.
An association has two ends. An association’s end is modeled by means of a UML Property which can be owned by the classifier involved at the related end of the association, in that case the association is said to be navigable as the source classifier can directly refer to the target instance (the instance at the other end of the association) by means of that property. Otherwise the property representing the association end may be owned by the association instance itself
see http://lowcoupling.com/post/47802411601/uml-diagrams-and-models-with-papyrus
Related
In an UML class diagram:
a) Do you have to state attributes that are aggregated? Or is it enough with the arrows indicating aggregation?
b) Do I have to add "id" as an attribute or is it a given?
Thanks.
You are using a shared aggregation in the picture. That does not have any defined semantics as per UML 2.5 (see p. 110). If you need a composite aggregation the diamond must be filled. In that case the aggregated object will be deleted along with the aggregating one (the latter must assure that constraint). In your model it makes no sense. No employee aggregates a department. Even vice versa I would have doubts or at least reason for discussion.
An id is only needed if it has a business purpose (e.g. an article number). If you transform your model to a database you introduce an artificial id for technical reasons. But on an abstract business level they are not modeled.
Your models only differ in the use of attributes for associated classes. The B variant is preferred. But you need to place the attributes as role names towards the associated classes (as -department and -branch). What you have placed in the middle of the connectors is rather the association name. Badly chosen with the + in front. Naming associations is rarely needed. So get rid of that. Role names shall be placed near the class that takes the role. Also it's a good idea to use the dot-notation to show that the roles represent owned properties. Just place a small black dot near the left hand side of both (near where the role names should go).
As for the dot-notation UML 2.5 states on p. 18:
Dot notation is used to denote association end ownership, where the dot shows that the Class at the other end of the line owns the Property whose type is the Class touched by the dot. See 11.5.4 for details of Association notation and 11.5.5 for examples.
Also as JimL. commented the A-version uses associations plus attributes which introduces redundancy. This is not illegal but likely not intended and at least leads to confusion.
What is an example of Navigability in UML diagrams? My professor has provided the follow figure, but I can't seem to figure it out:
This shows navigability. A can see (means it has an attribute referencing) B. In contrast B has no idea about/reference to A. As #JimL commented, your arrow is wrong and only used for stereotype definition. I'm referring to the unfilled arrow which indicates navigability of associations from which I assume you actually meant that.
UML 2.5 spec p. 18:
Arrow notation is used to denote association end navigability. By definition, all class-owned association ends are navigable. By convention, all association-owned ends in the metamodel are not navigable.
An association with neither end marked by navigability arrows means that the association is navigable in both directions.
And even more relevant p. 200:
Navigability notation was often used in the past according to an informal convention, whereby non-navigable ends were assumed to be owned by the Association whereas navigable ends were assumed to be owned by the Classifier at the opposite end. This convention is now deprecated. Aggregation type, navigability, and end ownership are separate concepts, each with their own explicit notation. Association ends owned by classes are always navigable, while those owned by associations may be navigable or not.
So you should use the dot notation instead:
The UML specs is an intricate pile of alternative notations that can drive you crazy. Explore with caution!
In real life, KEEP IT SIMPLE! Don't use "dot notation" and don't use x to denote non-navigability, unless your peers are familiar with it.
Use arrows for navigable associations. People are familiar with it, or if not they're intuitive enough.
I don't understand what the relationship between the two tables in the linked picture mean. And how can I code it?
It's with
virtual public Propriete Proprietes { get; set; }
Geert writes true things, but I think, you need more practical advice.
That one-directional arrow means, that the Enquette class has a field or method, that are of the class Propriete. In 99% it is a simply field of that type. Contemporary standard offers to use a point on the other side of the line for this.
The fact, that the arrow has no name on it, often means that the name of the field is propriete, or Propriete, according to the style accepted by the language and your company. (it is not required in UML standard, but it is widely used). According to the last paragraph of the question, it seems, your company uses this rule, too.
The fact, that there is no arrow on the other end of the line, does not mean, that there is no field or method in Propriete class that has a class of Enquette. (Though it meant that in 90-ties). It merely means we haven't decided yet if there are such fields or not. Or maybe, we consider it to be not important. I.e. it is undefined. The known lack of such connection must be shown by a cross instead of an arrowhead.
So, somewhere in Enquette you have a line:
Propriete propriete;
or
Propriete* Propriete; //if you are in C++
or even maybe
Propriete** Propriete;
or cited by you
virtual public Propriete Proprietes { get; set; } // apparently, C#
It could be either static/class field or instance field - it is not defined in the diagram.
And in the class Propriete there can exist the line:
Enquete enquete; // or some of the mentioned variants
And you are leaving the decision about its existence to the coder.
Notice, that a line without arrowheads means that really there are fields (or methods) for both ends. Simply we don't draw arrowheads at all if the line should show two of them.
So, really, you have a mistake in the question. It is NOT an unidirectional relationship. It is an unidirectional arrow showing a relationship, that MAY BE unidirectional.
The arrow at the end of the Association between the Classes (not tables) indicates that this end is navigable.
This is defined as an operation the Property at the end of the Association. The definition in UML 2.5 specs says:
isNavigable() : Boolean
The query isNavigable() indicates whether it is possible to navigate across the property.
body: not classifier->isEmpty() or association.navigableOwnedEnd->includes(self)
Furthermore it says about the Association Notation:
An open arrowhead on the end of an Association indicates the end is
navigable. A small x on the end of an Association indicates the end is
not navigable.
And about the Navigability on an Association
Navigability means that instances participating in links at runtime
(instances of an Association) can be accessed efficiently from
instances at the other ends of the Association. The precise mechanism
by which such efficient 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.
And to conclude something to keep in mind because this convention is still often used:
Navigability notation was often used in the past according to an
informal convention, whereby non-navigable ends were assumed to be
owned by the Association whereas navigable ends were assumed to be
owned by the Classifier at the opposite end. This convention is now
deprecated. Aggregation type, navigability, and end ownership are
separate concepts, each with their own explicit notation. Association
ends owned by classes are always navigable, while those owned by
associations may be navigable or not.
So now you should know what it means. How to code it depends on the programming language, the company standards, the architectural layer, your creativity, etc..
I can't seem to find a decent answer on the interwebs, though I'm sure it's been asked before.
Basically, I have an object that is composed of another object - so black diamond and line. When the parent dies, the object it composes dies. However, the object that is it composed of has a pointer back to the parent. What does this look like in UML?
EDIT: For example, a building may be composed of rooms, but the rooms contain pointers back to the building object
Thanks
You would use the owned end notation which is showing a dot near the owning class in the association connector.
An end Property of an Association that is owned by an end Class or that is a navigableOwnedEnd of the Association indicates that the Association is navigable from the opposite ends; otherwise, the Association is not navigable from the opposite ends. Navigability means that instances participating in links at runtime (instances of an Association) can be accessed efficiently from instances at the other ends of the Association. The precise mechanism by which such efficient 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.
From Superstructures ptc-13-09-05 p. 207
What is the differences between property owned by an association and a property owned by a class in UML?
is there a simple example helps me understand the differences?
The difference is more conceptual than anything else. If you have a property attached to an association, then you will have an association class, with the desired property.
Here is an example of a mailman sending letters to clients (the attribute weight is bound to the association):
The difference is very concrete, but traditionally ignored.
A is associated to B. A,B are classes.
If B end of the association is "association owned" and navigable, it means, that you can easily reach instance of B from A, either by reference, or by some method(s). It should be shown by arrow.
If B end is "classifier owned", you know a bit more. it means, that A has an attribute, that is a direct reference. (No functions or reference counting here). It should be shown by arrow and "dot"- a small black filled circle.
If you are going to B by a.smth.smthelse.b, it is arrow, but surely no dot.
If you are going to B by a.b, it is arrow and dot.
If you haven't decided yet, it is arrow again.
Traditionally modellers show arrows only. But it is not a good tradition, and is against UML standard. Diagrams are more useful if we decide as much as possible on them, not in code.
If both ends are navigable, both arrows disappear and you may see only dot(s).
The association lines with cross with dot on one side, or arrow on one side and only dot on the other are senseless.