I have three classes one is called
WorkCoordinator and it calls different service classes depending on an event passed to it, so if the event is trackIssue there is a TrackService class that handles some operations specifically for tracking and there is also a Track object. So you could have the following
WorkCoordinator -- (track issue) --> TrackService (has a list of Track objects)
How would you correctly represent these three in a UML diagram ? where everything starts with the workcoordinator which uses a TrackService and TrackService may have a function like add(Track track), where you would pass it a Track object to add to an array list within it say:
private ArrayList<Track> tracks;
and as add gets called, then a track is added to tracks.
Appreciate any insights, I was thinking something like this but may be totally wrong.
I have three classes one is called
Contrarily to an operation a class cannot be called, but it can be used.
WorkCoordinator -- (track issue) --> TrackService
when the event string is trackIssue the class WorkCoordinator uses the class TrackingService, but how ? Because in your diagram the class TrackingService only has the operation add that means that operation is called, even I have some doubt about that, more the fact we don't know from where the instance of Track given in argument comes from. If an other operation is called add it in the diagram.
About your diagram :
the role of the line between WorkCoordinator and TrackingService is unknown as it is, and then invalid. Because of the attribute trackingService probably you wanted to also show it as a relation, in that case the relation must completed.
TrackingService has two lists of Track, one though the attribute trackItems and an other one through the relation tracks. This is probably not what you wanted, and trackItems must be renamed tracks or the reverse.
to show the same thing through an attribute and a relation is legal in UML, but quite heavy because the reader must check they are the same thing, I encourage you to use only one of them, and to favor the relation when both classes are drawn.
your aggregation says TrackingService is composed of Track, are you sure this is the case and an aggregation must be used ?
How would you correctly represent these three in a UML diagram ?
The class diagram does not indicate at all that when the processed event is trackIssue the operation add (or an other) is applied on trackingService (with the right argument). Of course you can add a note to say that, but that note is a free text and only human can understand it.
To show that in a diagram you can use a sequence diagram or an activity diagram, depending on what you want to show.
The sequence diagram showing what happens during the execution of process can be (supposing a new instance of Track is created to be given in argument to add) :
event is supposed to be the argument of process, to name the instance of TrackingService I used trackingService being the name of the attribute, and item represents the created instance of Track to use it in the message add.
All of that seems vague, but this is normal because an interaction is not a behavior, and a sequence diagram focuses on message interchange between lifelines.
If you want to fully model the behavior of the operation process without ambiguity you can use an activity, and the diagram can be :
Additional remarks :
An event is generally much more than a name like trackIssue, so the parameter of process is not a string or that string is a complex form.
Track has getter/setter for the id but not for the name, seems strange. Are you sure the id is not only set (with name) when an instance is created ?
Related
I have a question regarding modeling on an Activity Diagram that has been bothering me for some time and I was not able to find any answers / Convention anywhere.
Here is an example to better understand my question:
Let say that I have two class named "flat" and "house". both are a generalization of the class "housing".
housing contain an attribute "residents" for the person living in it.
flat contain an attributes "floor" that says at which floor the flat is.
Here is the class diagram:
In an activity diagram, I want to represent the action of giving persons a housing.
this action can take either house or flat as input (so the use of "housing" type for the input pin is correct I think) as well as an undefined number of people.
I want this action to give an updated house or flat as output (not an updated housing as this would mean that information specific to the house or flat would be lost.
I don't really know if I must create two actions (one for house and another for flats) or if there is a way to reuse the action for both class and have a correct output out of it.
Here is the activity Diagram:
My question is: how to represent in an activity diagram, an action that is the same for different type of Object flows as input, and that give the updated Object flow as output (that may be therefore of different type)?
nb:
all type of object flow are class and inherit from a same other class.
I'm representing this in modelio but first had this issue in Cameo.
I'm Trying to fit as best as I can within the rules of UML Language.
Cameo is right in rejecting this model. Give Flat Floor expects a Flat and will not work with a House, but Assign Resident to Housing could return a House. I know, in your context it can only return a Flat, but how should the tool know that?
The correct way to capture this fact would be to add a postcondition to Activity Assign Resident to Housing that states that the type of the input and output pin will be the same.
However, it would be really hard to define a complete set of compatibilty rules that takes into account all the global and local pre- and postconditions and the tools would also be hard pressed to validate a model according to these rules. Therefore the UML specification choose the easy road and simply doesn't allow to connect the pins.
The solution is to use the transformation property of the ObjectFlow. Just assign an OpaqueBehavior that casts the Type House to the Type Flat. Cameo will then accept the model. It is the modelers responsibility to ensure, that this cast will always work, since no exception handling can be defined here. Maybe this should be documented with a local postcondition.
In your specific example there is an even easier solution: simply fork the ObjectFlow of Type Flat and omit the OutputPin of Assign Resident to Housing.
As a side note: Due to a bug in Cameo, you can change the type of the OutputPin to a more specific Type than that of the ActivityParameter. This is correct for InputPins, but should be the opposite for OutputPins. You could use this to let the Parameter be of type House, but the OutputPin-Type would be Flat.
The two flows (top object and lower control) in the blue frame could stay as they are. Give flat floor would commence only when it receives a Flat object and the control token is sent. In order to make the right action sort of optional I would just use the object flow, thus only triggering when a Flat object is passed. That would just be enough and no additional control flow is needed.
To make things clear I would also add a guarded flow from the Assign action to an exit reading [ house was assigned ] or the like.
i've this method findNegozio(insertID) used to find the element with insertID in a Collection.
So, findNegozio(insertID) is an operation that is often referred to in my sequence diagrams so I thought I would illustrate it as a sequence diagram.
The idea is to represent an iteration on a collection and take only the element that matches with the entered ID.
Could this be a good way to represent my idea?
is it useful to represent a frequent step of some sequence diagrams?
EDIT: Maybe with only one step is better OPT instead of ALT.
First three remarks :
For me your code is invalid because a return is missing after the loop => I suppose a variable result is added and initialized to null, set to the found item if exist, and finally used for a final return.
Are you sure findNegocio is not static ?
Why findNegocio is defined on Negocio and not on GestoreNegocio ?
A sequence diagram shows an interaction (partially or not) and focuses on message interchange between lifelines.
From the definition of your operation it is needed to decide whose messages are enough interesting to be shown in your sequence diagram. I don't think the details concerning the list and iterator have to be shown, they are very classical, the goal is not to explain how to work with Java builtin classes.
To break the loop you have the fragment break, so your sequence diagram can be (I added a caller because my tool does not manage lost/found messages) :
But perhaps the main information shown is the use of GestoreNegocio and the loop by itself is not really interesting ?
State diagrams in UML are always constructed for a specific class (that is, to describe the behavior of instances of that class). Thus, every state diagram is associated to a specific object for which it defines its behavior. What is the name of this object? the closest I could find in the UML standard is the term 'context object', as in here (section 14.2.3.1 in UML v2.5.1):
The event pool for a StateMachine execution belongs to either its context Classifier object or ...
But I could not find anyone that uses this term.
I use an answer to not have to cut the following in several comments.
State diagrams in UML are always constructed for a specific class
You have to speak about state machine, not about diagram, and in your case visibly you speak about behavior state machine (not about protocol state machine).
A diagram is just a picture showing a part of the model.
Thus, every state diagram is associated to a specific object for which it defines its behavior. What is the name of the object?
That depends, if your state machine defines the behavior of an operation then your object is that operation and its name is the name of the operation.
that is, to describe the behavior of instances of that class
If I well understand this is from where your error comes from. You are focused on instances of class, but a state machine does not define the behavior of instances of a class, so to try to know the 'name' of theses instance as no sense.
Perhaps someone who has worked on the still-unadopted Precise Semantics for State Machines specification at the OMG will correct me if I’m wrong, but I believe there are three possible execution contexts.
The first is that of an “active class”, where each instance runs in its own thread and you send signals to it. The second is that of a normal class, where you call operations on or send signals to a normal instance, in the usual way. The third is that of a BehavioredClassifier, where each instance starts a special classifierBehavior as soon as it is created.
§13.2.3.5 of the UML 2.5 spec says:
The receiving object becomes the context object for the execution of
any invoked methods.
NOTE. Methods of a Reception are always invoked asynchronously, while
the methods of an Operation may be invoked either synchronously or
asynchronously, depending on how the Operation is called.
A state machine is defined for one of those execution contexts to determine how an instance will respond to a particular event, given its current state.
Yes, every state machine (possibly depicted in a diagram) is associated with an object, but it is not some specific object with some special name. Rather, a state machine governs how every instance of a particular class will respond to events, given its current state. And the name of an instance is whatever variable happens to hold a reference to it.
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.
Intro
When designing UML activity diagrams I often encounter a rather simple problem for which I have to draw a rather complicated solution. I'm looking for an UML conform shortcut or more simple solution for the following problem.
Problem
Lets assume we have a class Parent with associations to different Children:
And we have an analog Constalation with the class Result and three chidren Result Part A, etc.
Now I want to refine an activity, which accepts a Parent object as input and produces an Result as output:
In the desired refinement, I want to I want to access the children or create the result from the result parts.
Current Solution
If I want to access the children or create the result from the result parts, I always have to introduce extra activities for those rather simple tasks:
Question
Are there any shortcut or simplification here, to access, extract or merge the children of an object? The desired Solution should be legal standard UML.
Something as simple like this would be nice:
UML does not define complex object creation element. If you need to construct result object which is composition of child objects, you have to present action. You should define action with resulting pin of composed type and input pins of child object types for each one. Action can start execution only if all input pins contain expected object.
For separation of child object from composed object use transformation as it is described in Waog's answer.
In your current solution example remove join element before merge result Children action, and connect all object nodes to this action. Remove extract input Children action and use transformation.
Answer on how to split objects
I found an answer on how to split a composed object in Martin Fowlers UML distilled myself, after getting a hint from #xmojmr
The book states:
Source: UML Distilled: A Brief Guide to the Standard Object Modeling Language
By Martin Fowler - on Google Books
I still don't know, if it's allowed to omit thos transformation-notes and just draw the pins and transitions!?
Missing Answer on how to merge objects
I'm still missing the answer on how to merge objects to a composed objects without introducting a merge-activity.