Handling composed objects in UML activity diagrams - uml

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.

Related

How do I model UML Activity that calls operations from the same class?

Suppose I have some Class (specialization of BehavioredClassifier) with three operations A(), B() and C() and the operation C just calls operation A and then B. UML's CallOperation action (see 16.3.3.1 Call Actions) requires target object which in this case will be a context object in UML parlance as described in section 13.2.3.4 Behaviored Classifiers of UML Specification:
a Behavior that is the ownedBehavior of a BehavioredClassifier has that BehavioredClassifier as its context... If a Behavior has a context , then an execution of the Behavior always has an associated context object that is an instance of the context BehavioredClassifier (as long as that BehavioredClassifier is instantiable)
UML Activity diagram will look rather ugly due to Read self activity (see 16.4.3.4 Read Self Actions in UML Specification):
I have a feeling that I read somewhere that Read self can be omitted under some circumstances and target may be assumed to be context object in that case.
Is there such clause in UML documentation?
I couldn't find such clause in UML Specification, but found the solution, described below.
First so called ActionInputPin is to be used for target. According to paragraph 16.2.3.3 Pins:
An ActionInputPin provides values by executing another Action. When an Action is enabled by other means, the
fromActions on any ActionInputPins owned by the Action are also enabled. The fromActions must execute before the Action owning the ActionInputPins, and the outputs of the fromActions are placed in the corresponding ActionInputPins. The process recurs on any ActionInputPins of the fromActions. In the case that ActionInputPins are used for all inputs, this forms a tree structure that is an Action model of nested expressions, bottoming out at Actions that have no inputs (such as ReadVariableActions or ReadSelfActions)
Then Annex B: UML Diagram Interchange of UML Specification that
... enables interchange of the purely graphical aspects of UML models that modelers have control over, such as the position of shapes on a diagram and line routing points (UML DI). This information must be interchanged between tools to reproduce UML diagrams reliably.
states in paragraph B.4.3 Activity Diagram Labels that
ActionInputPins with fromActions that are ReadSelfObjectActions may be shown in a shorthand notation that shows only the ActionInputPin and nearby the string “self” interchanged as a UMLLabel with the ReadSelfObjectAction as modelElement.
The above clause is illustrated in table Table B.1 UML Shapes as follows:
Thus the model in question is transformed into the neat version shown below:

Activity Diagram: Reusing Activity/Action With different inherited type of object flow as output

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.

Service Class representation in UML

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 ?

Can this diagram represent an Iteration/for each in a Collection? Sequence Diagram or Activity Diagram?

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 ?

Options for representing string input as an object

I am receiving as input a "map" represented by strings, where certain nodes of the map have significance (s). For example:
---s--
--s---
s---s-
s---s-
-----s
My question is, what reasonable options are there for representing this input as an object.
The only option that really comes to mind is:
(1) Each position translated to node with up,down,left,right pointers. The whole object contains a pointer to top right node.
This seems like just a graph representation specific to this problem.
Thanks for the help.
Additionally, if there are common terms for this type of input, please let me know
Well, it depends a lot on what you need to delegate to those objects. OOP is basically about asking objects to perform things in order to solve a given problem, so it is hard to tell without knowing what you need to accomplish.
The solution you mention can be a valid one, as can also be having a matrix (in this case of 6x5) where you store in each matrix cell an object representing the node (just as an example, I used both approaches once to model the Conway's game of life). If you could give some more information on what you need to do with the object representation of your map then a better design can be discussed.
HTH

Resources