I am currently doing several UML tasks for practice and I got stuck on one of the tasks. In general, I want to modell moving objects. When a moving object moves, they go to a neighboring field (a field may have multiple neighbors). There are two kinds of objects, one of each behaves differently and "Object 2" moves 2 times faster then "Object 1". So basically I have to represent that the "Object 1" moves half as much as the "Object 2" at the same time. How can I make the movment dependent on velocity and shows this on the diagrams? Here is my basic class diagram and my sequence without the velocity:
I guess I should make the Move() functions dependent on the velocity too but I do not understand if that is enoguh or somehow I must represent on sequences that "Object 2" steps two times more thent "Object 1" at the same time.
Doesn't seem like something you would model in a class or sequence diagram beyond what you've already done. The fact that an object's movement speed depends on its velocity should be readily understandable if you have class called MovingObject with a velocity member and a Move() method.
If you really do feel like you need to model that, I'd look into using a UML timing diagram.
Just use a combined fragment with a loop operator that will include the getNeighbor message exchange. The parameter would be the velocity. It would look like this:
loop (velocity)
Of course you also need to handle the cases, where there are not enough neighbors left or when multiple neighbors are returned.
Some further remarks:
If the velocity is a constant, you could define it with a default value in the subclasses. Otherwise they seem to be identical and would be superfluous.
f1 seems to be the name of the association end at the field side. You should show this.
You are not using the parameter f of the move() operation. Why did you model it?
Related
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()
I am not entirely clear about multiplicities.
From what I understand, (1..*) close to instructor class means 1 Instructor can have many Courses.
And (1..1) near course class, means 1 class can have 1 instructor.
Is this a correct reasoning?
Note: Please ignore contents of Course class
First: the round brackets around the multiplicities are wrong. Leave them away.
Your diagram "means" that an Instructor has exactly one relation to Course. Additionally it has a private property teachingCourses as a list. The semantics ot the 1..1 is absolutely not transparent. Vice versa a Course has 1..* Instructors (hopefully not at the same time). Plus it has a private property leadInstructor (your naming is not orthogonal here).
Now, most likely you meant this:
There's an instructor to hold 1..* courses and a course has exactly one lead instructor. I omitted the local properties and used role names marked as owned properties (the dots). That eliminates the redundancy from your diagram.
Note: as #Ister commented, 1 is a shortcut for 1..1. Both mean "exactly one". Where a .. appears in a multiplicity it separates lower bounds (on the left) from upper bounds (right).
Let's say two domain objects: Product and ProductVariety (with data such as color, size etc). The relationship between these two is one-to-many. Conceptually saying in the domain driven design, the ProductVariaty should be a value object, which is not the same object once its data is changed. From the implementation point of view, however, it is better to have some sort identification for the ProductVariaty so that we know which ProductVariety is selected and so on. Is an only solution to convert it to an entity class?
The following is a code segment to illustrate this situation.
#Embeddable
class ProductVariety {...}
#Entity
class Product {
#ElementCollection
private Set<ProductVariety> varities;
...
}
Conceptually saying in the domain driven design, the ProductVariaty should be a value object, which is not the same object once its data is changed
That's not quite the right spelling. In almost all cases (many nines), Value Object should be immutable; its data never changes.
Is an only solution to convert it to an entity class?
"It depends".
There's nothing conceptually wrong with having an identifier be part of the immutable state of the object. For example, PANTONE 5395 C is an Identifier (value type) that is unique to a particular Color (value type).
However, for an identifier like PANTONE 5395 C to have value, it needs to be semantically stable. Changing the mapping of the identifier to the actual color spectrum elements destroys the meaning of previous messages about color. If the identifier is "wrong", then the proper thing to do is deprecate the identifier and nominate a replacement.
Put simply, you can't repaint the house by taking the label off the old paint can and putting it on a new one.
In that case, there's no great advantage to using the identifier vs the entire value object. But its not wrong to do so, either.
On the other hand, if you are really modeling a mapping, and you want to follow changes that happen over time -- that's pretty much the definition of an entity right there.
What it really depends on is "cost to the business". What are the trade offs involved, within the context of the problem you are trying to solve?
Note: if you really do find yourself in circumstances where you are considering something like this, be sure to document your cost benefit analysis, so that the next developer that comes along has a trail of breadcrumbs to work from.
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
I'm creating a sequence diagram, and one of the classes is being observed by another class. The observed class is calling update in the observer every 5 seconds in a loop. I need to show this in the sequence diagram. Is there a way to show it looping indefinitely out of sequence as it were?
Or does it not make sense in the context of a sequence diagram; should I not include it? Or should I include it in a different type of diagram?
You can use a box enclosing the message send arrow (and whatever else is inside the same repetitive construct).
See this tutorial for an example.
link to larger image (archived)
Just adding a clearer picture because this one at #joel.tony's answer is damn blur.
As you can see the loop happens inside the frame called loop n. There is a guard, array_size, which controls the loop's iterations.
In conclusion the sequence of the messages inside the loop n frame (those between DataControl and DataSource objects) will happen array_size times.