UML Aggregation Multiplicity - uml

What do the diagram's multiplicity values mean?
Do they mean each ShoeStore must have 1 instance of NikeShoes, and that the same instance can be part of many ShoeStore instances? In other words, many ShoeStores might have the same pair of shoes (an instance, not the type) to sell? Thanks.

The diagram shows a shared aggregation relation. As per UML 2.5 this has no defined semantics. P. 110:
shared | Indicates that the Property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.
So what is left is an association (except there is some hidden document explaining the exact semantics of the diamond). And that means you can have 1 NikeShoes in 0..n ShoeStore. What ever that might mean.
Regarding multiplicities: pp. 34 of UML 2.5 says
A multiplicity with zero as the lower bound and an unspecified upper bound may use the alternative notation containing a single star “*” instead of “0..*” multiplicity.

The 1 multiplicity is a defined shortcut for 1..1, meaning that every instance of ShoeStore must have at minimum and and maximum 1 instance of NikeShoe.
The reverse * multiplicity is a defined shortcut for 0..* which means that an instance of NikeShoe can be part minimum 0 and maximum an infinity of instances of ShoeShop.

Related

UML Activity Diagram: Get the multiplicity of a class's 0..* attribute

How does one go about getting the number of elements in a class's attribute that has 0..* multiplicity?
I can only think of either using an << iterate>> construct to do so but that seems silly or a counter whenever something is added. This seems inelegant if not inefficient.
If you want to refer to the cardinality of an attribute in an activity diagram, you can use the size() function. Example:
If your activity diagram is meant to be read by humans, not by machines, you can also just simply write "number of elements in object.attr".
If you want to access the cardinality in order to create a loop, you might prefer the expansion region. An iterate construct in activity diagrams can be achieved by using an expansion region with mode = iterative. Suppose class Order has attribute orderline of type OrderLine[1..*]. The following diagram shows how to iterate over all orderlines.
See section 16.12 of the UML 2.5.1 specification for more information.
A multiplicity of 0..* means that for a given instance a of A there is a collection of associated instances of B that has has at minimum 0 and at maximum * (i.e. no upper limit) elements:
The same is true for an attribute b:B [0..*] that a class A could have.
The number of elements in the collection is called cardinality. In a constraint, you can refer to the cardinality with
self.b->size()
There is also a convenient way to check if the collection is empty or not:
self.b->isEmpty()
self.b->notEmpty()

Proper modeling on UML class diagram

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.

UML composition 1.* and 0.*

I have a question in UML. I'm a beginner in UML and I do not know if I can do this :
You can't. A composition means a whole/part relationship and it can only be 0*-1, 1*-1 or 0*-0..1 at most.
For more information on the subject I'd read this:
https://www.uml-diagrams.org/composition.html
EDIT: Think about what a whole/part relationship is. A bedroom is part of a house, but the same bedroom cannot belong to multiple houses. However, a house can have multiple bedrooms. This is the same kind of relationship as in the house/bedroom case.
In addition to Carlos Manuel Hernadez's answer, the multiplicity in a composition relationship is restricted in the end that touches the whole so that in the upper limit it is at the most 1 for which only the following are allowed: 0..1, 1 and 0 in cases of redefinition. The UML standard 2.5.1 on the page 122 says:
Composite aggregation is a strong form of aggregation that requires a part object be included in at most one composite object at a time. If a composite object is deleted, all of its part instances that are objects are deleted with it.
NOTE. A part object may (where otherwise allowed) be removed from a composite object before the composite object is deleted, and thus not be deleted as part of the composite object.
And on the page 207 there is an example:
The other end, as far as I know, has no restrictions so that any multiplicity is allowed (0, 1, 0..1, n, n..m, *, etc.)
With respect to the cascade elimination, this is not limited only to the composition ralationship. You can model an association without any kind of aggregation and put a constrain or an annotation on it to indicate that the existence of an object is conditioned to the existence of the other
Sorry for the bad English, my native language is Spanish

Precise semantic of annotated associations with { bag } and multiplicity bound constraints

Suppose I have A ---r1 {bag} [1..2]--> B in a UML class diagram (that is, r1 is an association from A to B and is annotated with {bag} and multiplicity [1..2].
My Question: if a:A is an instance of A, is the following collection valid?
a.r1={(b1,1),(b1,2),(b2,1)} //collection contains two copies of b1 and one b2
In other words, multiplicity bounds (i.e., [1..2]) apply to the association when it is interpreted purely as r1:A --> B, or it applies to r1: A --> Bag(B)? In the former interpretation, the above collection is valid, since r1 contains at most two instances of B, but in the latter it is not, since r1 contains three elements of Bag(B)! which interpretation is correct?
Multiplicity constraints in UML are explained in Chapter 7.5.3 of UML document as I am referred to in this question.
p.s.1: A similar question arises when we substitute {bag} with {seq}.
p.s.2: I added haskell tag to get comment from large haskell community here as #xmojmr suggested. Thanks to #peter that nicely draw the pictures in his answer.
As stated in specs, Bag is unordered, nonunique collection.
However this describes the relation between the elements you are pointing to.
So your example can be expressed in either way:
This means that A has reference to one to two B instances, and those references are stored in a Bag (or any nonunique, unsorted collection; but that is implementation detail).
To answer your question: no, because the Bag contains three instances of B, whilst the allowed maximum is two B's.

Association of n to 1 objects in a UML class diagram

Is it safe to say that in a UML class diagram, if there is an association of n to 1 objects, then the association arrow is pointing from the class associated with n objects to the class associated with 1 object?
n ----> 1
Not in general. The arrow direction in UML corresponds to navigation possiblities. Hence, if your arrow points from the n objects to the 1 object it means that in your resulting code each of the n objects can access that 1 object. Of course you may also want an association in which that 1 object can access the n objects, so the arrow points in the different direction. (If no arrowhead is given it means that the n objects can access the 1 object and vice versa.)
Not precisely. It depends on the type of association. If its an aggregation then the default is bi directional navigability, but you can specify the navigation to be one way. I think that it is entirely up to the designer to decide the direction of the navigation between objects.
No. At least in object oriented programming, the one class that has the "1" association (reference in OOP) could equally well have the many references to the other class.
It depends on the design you make.
I thought the arrow was more about navigability (i.e. an arrow from A -> B shows that class A knows how to get to B but B does not know how to get back to A) than expressing the cardinality of the relationship.
If I can suggest, there are 3 different notions:
1 - Navigability which is modeled by arrow
2 - Cardinality which is modeled by number or star for 0..n
3 - to who belongs the end point of the association which is modeled by a dark point
please see extracted from the norm.

Resources