0

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:

enter image description here enter image description here

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.

Tom
  • 43
  • 4
  • *velocity* is defined in mother class => you do not have to define it again in child classes. You missed the multiplicity "*" for neighbors (a field can be alone I suppose so not `1..*``) . Out of that you do not indicate the impact of the velocity when you call move. For instance is velocity an integer and when valuing 0 object stay in current field when move is called, when valuing 1 object moves to the a next field when move is , is valuing 2 object moves to a next field of a next field when move is called etc ? how the object choose the field among the neighbors ?. A field can refuse ? – bruno Dec 01 '20 at 16:49
  • @bruno The reason why I define the velocity again in the child is because all objects has a base velocity (the mothers) and some kind of objects has a different value for this (so one of the sublclasses has the mothers velocity, the others has twice bigger). It is true that in both it is unnecessary. For choosing a new Field I tought after the getNeigbors() function called the user will choose one of them (in sequence it is f2) and move there. It is not enough? Using the velocíty is not clear for me too. I wanted somehow to express that while Object A takes a step, Object B takes two steps. – Tom Dec 01 '20 at 18:15
  • out of joke you just move the problem, what a 'step' is ? in the real life an object has a position, and moving change that position kwowing the speed and the duration of the move, and may be the surface where objects move is composed of fields etc. You need first to define your 'simulation' in detail => to decide 'what to do' , then after you will be able to see 'how to do' – bruno Dec 01 '20 at 18:27

2 Answers2

0

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.

Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
  • While I agree with the timing diagram I think that modeling of movements is a non-trivial task. I would understand that as some real-time task. And that would need some scheduler to handle moving objects (which is missing in the design). – qwerty_so Dec 01 '20 at 14:47
  • @qwerty_so How that scheduler would look like? – Tom Dec 01 '20 at 16:21
  • @Tom I will try to make an answer, but I'm busy at the moment... – qwerty_so Dec 01 '20 at 17:35
  • @Tom Meanwhile you might look into https://stackoverflow.com/questions/954193/is-there-an-inituitive-uml-approach-to-depict-threads and/or search for "uml threads" on SO. As said: it's not trivial. – qwerty_so Dec 01 '20 at 18:41
0

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?

Axel Scheithauer
  • 2,758
  • 5
  • 13