What are these UML symbols? - uml

What are are the meanings of symbols marked 1,2 & 3 ?

The first one is aggregation.
The second one is a connector for the comment
The thirs is a dependency.

1) aggregation (special form of association)
2) this is simply the connector for the comment
3) generic dependency

1) the open diamond means weak form of aggregation. This relationship denotes that
the aggregate class (the class with the white diamond touching it) is in some way the “whole”, and the other class in the relationship is somehow “part” of that whole.
2) Similar notation is used to represent an interface, but I don't think this is the case here, ergo - I don't know what it is.
3) The dashed arrow is a dependency relationship or ‘using’ relationship. This relationship simply means that ConcreteBuilder somehow depends upon Product. This is very weak relationship and is not implemented with member variables at all.

Related

How to model different variations of similar classes in an UML Class Diagram?

Trying to implement a class diagram and I am not sure how should it done properly. Here is the problem:
Miners can extract gold, silver and coal (the mines are homogeneous, always contains one type). In addition, there are some dangerous mines: e.g some might collapse or be radioactive.
How can I represent this on a class diagram? First, I thought it can be done with one Mines class. From that with generalization I candefine the collapsible and radioactive mines. But I can't decide how to deal with the different material types. Should that be classes too or attributes in the Mines class?
The simpler the better. Without specific behavior in the statement depending on the extracted substance it is enough to have only one class Mine, and the the list of possible substances being known an enumeration is enough. Because a mine produces only one substance the multiplicity is 1.
The statement doesn't say if the mine can both be radioactive and collapse or not.
Supposing a mine can both be radioactive and can collapse, you can use an attribute for each danger:
It is also possible to use a enumeration for the danger and the multiplicity 0..2 but it is also necessary to have a constraint saying each danger appears at most one time, so this is not a simple way.
Else if even less probable a mine can have at most one danger you can again use a enumeration with the multiplicity 1:
or with the multiplicity 0..1:
The best way to model this is by defining the material in the mine as an enumeration. An enumeration is a data type, which you can use to define an attribute, as follows:
The dependency arrow from Mine to Material is redundant, because it is already implied by the fact that it is used as an attribute type, but in a more complex class diagram, I find it helpful to easily see which enumerations are used by which classes.
I did not use generalization for the various types of mines, because the subclasses would not have special features, so I go for the most simple solution.
I did not use generalization for the dangers, because a mine may be both collapsing and radioactive.

UML constraint across three associations?

Let's say I have class A with associations to classes X, Y, and Z, respectively. I need to indicate that only one of these associations may be instantiated for any given instance of class A (so, an xor constraint). I know how to do this if the constraint is just across two associations. Obviously I can just make three seperate xor constraints (X-Y, X-Z, Y-Z) but I'm wondering if there is a better/cleaner/proper way to do it?
edit: The multiplicity constraints on the respective associations are not the same. Using an abstract class or interface will not work. Furthermore, a note is insufficient. I need to use some sort of formalized structure, preferably something standardized (e.g. by OMG) to express this because I am programmatically processing the model elements (i.e. it isn't just a picture). I understand how the underlying model for UML provides for this facility. It also specifies (though slightly vaguely) how it should be notated. I guess my main issue is, in fact, with finding a tool that allows me to make that notation. I don't think MagicDraw does so. I should have stated these things earlier.
FWIW, I'm using MagicDraw. It would be a nice bonus if the I could do this in a way that MagicDraw actually understood. I can live with it if that isn't possible.
The xor constraint is just a stylized and rather under-specified constraint for the 2-way case.
You can define an explicit constraint (in Complete OCL) as:
context A
inv OnlyAorBorC: A->size() + B->Size() + C->size() <= 1
MagicDraw may allow you to specify a similar contextual Constraint on A.
If "X", "Y" and/or "Z" can be somehow generalized (I mean, if you not doing this puraly for a conditional flow control), you can make an interface (or and abstract class) "I" for example, and make "X", "Y" and "Z" implement this interface. Then, you put an association with multiplicity 1 between A and the interface I.
See the diagram below:
Edit: The example above doesn't work in the case of A having different cardinalities between X, Y and Z. For this case, the only way that I can see is use an UML Constraint to restrict those relationships. You can define a Constraint in UML putting some OCL expression between curly braces. E. g.
Here, account owner is either Person or Corporation and this {xor} is predefined UML constraint.
I'm not sure about the details of your cardinalities requirements but, a combination between this {xor} and the interface example that I gave might be enough. At least it gives you a little bit more of options, like:
If you need to know more about the UML constraints subject, I got this example from uml-diagrams.org: http://www.uml-diagrams.org/constraint.html

UML Aggregation with and without arrow head

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

Using variables in UML multiplicities

I was running a tutorial today, and a we were designing a Class diagram to model a road system. One of the constraints of the system is that any one segment of road has a maximum capacity; once reached, no new vehicles can enter the segment.
When drawing the class diagram, can I use capacity as one of the multiplicities? This way, instead of having 0..* vehicles on a road segment, I can have 0..capacity vehicles.
I had a look at ISO 1905-1 for inspiration, and I thought that what I want is similar to what they've called a 'multiplicity element'. In the standard, it states:
If the Multiplicity is associated with an element whose notation is a text string (such as an attribute, etc.), the multiplicity string will be placed within square brackets ([]) as part of that text string. Figure 9.33 shows two multiplicity strings as part of attribute specifications within a class symbol. -- section 9.12
However, in the examples it gives, they don't seem to employ this feature in the way I expected - they annotate association links rather than replace the multiplicities.
I would rather get a definitive answer for the students in question, rather than make a guess based on the standard, so I ask here: has anyone else faced this issue? How did you overcome it?
According to the UML specification you can use a ValueSpecification for lower and upper bounds of a multiplicity element. And a ValueSpecification can be an expression. So in theory it must be possible although the correct expression will be more complex. Indeed it mixes design and instance level.
In such a case it is more usual to use a constraint like this:
UML multiplicity constraint http://app.genmymodel.com/engine/xaelis/roads.jpg

Class diagram relationship diamonds

When creating relationships in an Object Class Diagram for an Object Relational Database, should the diamonds on the ends of the relationship links be filled in or not.
Here is an image of my Class diagram:
http://canning.co.nz/Weltec/Class_Diagram.png
It's a choice between Composition and Aggregation, which Wikipedia explains quite well.
In practice though, I think a valid answer is to just not worry about the difference, unless it's a school assignment. I've found that trying to make very detailed UML diagrams isn't terribly useful in practice.
Composition relationship has a coloured diamond shape structure ending at a class if it belongs to a 'is a' relationship (i.e- the entity cannot exist without the parent class) whereas the aggregation has an empty diamond shape ending at a class if it belongs to a 'has a' relationship (i.e- the entity can exist without the existence of the parent class.
A full diamond denotes Composition, or a 'owns' relationship. You use it when the referenced entity can't exist without the class representing it. An example would be order to order item. The order item just doesn't make sense without the order.
An empty diamond denotes Aggregation, or a 'has' relationship. A quick glance at your diagram makes me think this is the correct diagram element to use in your case.
But I agree with #mpartel: If there aren't any specific requirements to distinguish between the two just ignore the diamonds.

Resources