How to use context properties in an Activity diagram in UML? - uml

Considering the following class diagram:
The class System is active and its behaviour is to continuously
call filter on PressureSensorFilter passing
PressureSensor.Pressure as argument
call Display.show passing the output param of
PressureSensorFilter.filter as argument
I would like to model the behaviour of System through an ActivityDiagram.
The main challenge in doing this is accessing the property PressureSensor of System.
After reading the UML 2.5 specification, I believe that the only way to do this is to use ReadSelfAction(pag 457 UML 2.5 spec) and ReadStructuralFeatureAction (pag 466 UML 2.5 spec) as depicted by the following Activity diagram:
where
ReadSelfAction gives as output a current Instance of System.
ReadPressureSensorFe.. is a REadStructuralFeatureAction that reads the property PressureSensor of the object give at its input pin which in this case is the current Instance of System.
CallBesselFilter.filter Action and CallDisplay.show Action are two CallOperationAction(s) that call PressureSensorFilter.filter and Display.show respectively.
The issue with this is that is very convoluted and unclear.
Is there any less convoluted and more clear way to describe the behaviour of System through an Activity diagram?

The ReadSelfAction as extra action is superfluous. You can reduce the control flow like this:
The pressure is read by the filter from the Pressure class' property. The filtered output is sent to Display and looping....
You should look into SysML. It's designed to cope with exactly that kind of problems you deal with.

It all depends on what detail you would like to provide in your activity diagram. The diagram you provide is correct. By the way, its level of details could be directly used to generate code. If you would like to describe behavior more abstract, do not use actions like read structural feature etc. But in your example, it is very good and precised way of description.

Related

understanding dependency relationship in UML component diagram

I'm struggling at understanding UML component diagram.
I've just been through the "assembly connectors" and here's what I (think I) understood:
the circle represents an interface, which I understand as a set of functions that a component can offer to the others.
the half-circle... well, don't know how to call it, but it says something like "there's some functions I need in order to operate correctly". In the image, I guess that an order must have access to functions that return details of the Customer (e.g: methods GetName(), GetAddress(), etc.), that's why it has the assembly connection with the Customer Details interface, provided by Customer.
My question is: why is there a dependency relationship arrow from the interface which Account provides (AccountDetails) and the interface which Order requires (Payment)?
The link of this image doesn't explain it.
The assembly connector (two shown on top) is a kind of provisional concept. You know that there should be an interface used instead, but have not yet made up the details. This is a connector which looks like socket/lollipop. But it's a connector.
The separate lollipop/socket are concrete interface uses. These are real elements. The interface itself is not actually shown (you will have a separate diagram showing the details). But to make clear that the depending interface is related to the providing one you draw a dependency.
Simply spoken, the above is something in the middle of a design phase. Finally all assemlies should be replaced by provided/required interfaces.

How to parameterize a UML sequence diagram and apply it to multiple object instances?

I would like to to create a sequence diagram to show some interaction, and then use that sequence diagram as an interaction occurrence (sub-sequence) on other sequence diagrams. The point is I would like to apply the sub-sequence each time to a different object instance that is involved in the interaction in the sub-sequence. In my case the instances are simply various file artifacts. Is there any legitimate way of doing this prescribed by UML?
EDIT: some more clarification of my context:
I have 2 main sequence diagrams where I want to reuse the sub-sequence as an interaction occurrence
on the 1st main sequence there is one file for which the sub-sequence has to be applied 3 times
on the 2nd main sequence there are 3 different files for which the sub-sequence has to be applied 3 times
the files are read by the same object instance
I model reading from a file by a call arrow stereotyped as <<read>> to a on object instance which represents the file.
I need to reference the file somehow in the sub-sequence, but I haven't found a good and simple way of doing this.
Complicated, but formally (almost) correct solution with Collaborations
Just using InteractionUses is not enough, because this doesn't allow you to assign the actual roles in the main interaction to the generic roles of your used interaction.
Collaborations, CollaborationUses and Role Bindings can be used for this.
See my example here:
This defines a Collaboration with generic roles sender, relay and receiver and shows the interaction between them.
You can now use this collaboration in a concrete situation:
Class S uses the Collaboration two times with different role bindings to its parts (A, B and C are assumed to be able to send and receive Sig1).
With these definitions you can now create your main sequence diagram:
Unfortunately, this is not correct UML, even though there is an example in the specification (I filed an Issue https://issues.omg.org/browse/UMLR-768). You will have to fake this notation until the taskforce comes up with a fix. How to fake it, depends on how strict your tool implements the specification.
Advantage: formally correct and versatile solution, backed by an example in the specification
Disadvantage: complicated and difficult to explain, not completely usable, because of a bug in the specification
Basically there are three different ways to specify such situations.
Using a gate. Whith gates you specify the sequence with messages that start or end at a gate that is defined and in most tools (if usable at all) not shown explicitly. Instead it is modelled with messages starting or ending at the interaction border.
Similar as gates are lost and found messages. These are special messages that pass out the control to another sequence or returns from one. Such as in the case before you can define a set of further diagrams specifying the interaction in more details.
Using abstraction, which is my favorit for most of the cases. This means you extract the common interface from the classes and specify the interaction against the interface instead of the concrete classes.
Use an Interaction with Parameters:
Now we would like to reference the Lifelines of the main Interaction in the arguments of the InteractionUse. Unfortunately, in UML this is not possible, since arguments are ValueSpecifications and they cannot reference another modelelement.
However, NoMagic suggested and implemented an additional ValueSpecification, called ElementValue, that does exactly this. I think this would be a valuable addition to UML and hopefully it will be added some day. Up to then, only MagicDraw users can use this solution (as far as I know).
With this non standard element, we can model this:
The connection between the lifelines is now via the arguments for the parameters of the generic interaction. Technically the lifelines would not need to be explicitely covered by the Interaction Use, but I think that it makes sense to do it (shown in my tool with a non standard circle on the border of the Interaction Use).
Advantage:
compact and versatile solution, almost conformant to the standard
Disadvantage:
uses a non standard model element, currently only available to MagicDraw users.
pragmatic non conformant solution with covered lifelines:
The collaboration and parameter solutions allow to specify it (almost) formally correct. However, in many cases, a simplified model would be sufficient. In your case, for example, you only have two participants and they have different types. So, even though there is no formal connection between the lifelines of the used interaction, and those of the main interaction, there would be no ambiguity. You could use the covered attribute of the InteractionUse to specify, which of the lifelines (files) you are targeting at a specific InteractionUse. Could that be the pragmatic solution, you are looking for?
Advantage:
compact solution
Disadvantage:
not conformant to UML, ambiguous in more complicated situations

Linking activity diagram to entities to be accessed

How do we represent in an Activity Diagram, which entities are to be accessed or updated? Is this is to be done as part of an activity diagram, or to be done separately?
You specify which Classes are accessed or updated using Pins on an Action or using an ActivityParameterNode on an Activity. Those Pins look like little squares on the periphery of the Action, or rectangles on the diagram frame of an Activity, and you connect OutputPins to InputPins using ObjectFlows (which unfortunately look just like the ControlFlows that connect Actions together). Here's an example from the UML 2.5 spec:
Now, to answer what I think you are really asking. I think you want to know how to navigate to instances of Classes in your model. To do that from an Activity, you use a ReadStructuralFeatureAction to read properties from the Class instance that owns the Activity you're specifying. The values flow out of an OutputPin. Using ReadStructuralFeatureActions you can navigate anywhere your instances allow. (Note that when a Property is owned by an Association rather than a Class, you use one of the ReadLink*Actions specializations of Action.)
Please see Part 4 of Conrad Bock's excellent series, UML 2 Activity and Action Models,
Part 4: Object Nodes for a better understanding.
You can use either
a dependency (dashed line) or
an object flow (solid line) to show that an action is interacting with an object or
an information flow (stereotyped with <<flow>>). This way you can specify one or more classes which control the information that is flowing (in the example it is FileTypeObject).

How to show this flow using UML?

I have a simple flow which I would like to describe using UML in best way possible. I have no experience with UML and do not want to chose ridiculous diagram type.
DataA --> ProcessorA --> DataB --> ProcessorB ... --> DataN -->ProcessorN
In nutshell, Data is collection of data in some structure and Processor x transform input data into data to be used by Processor X + 1.
Where Data and Processor are actual classes and it would be nice to show how this works in code - for processing a certain data usually the new processor must be created with the data object, something like process() method invoked on it which returns data as input for next processor.
I tried to study dynamic UML diagrams but I am not sure which type is best to use for this.
Activity diagram is a perfect choice for data flow behaviors. You can use them to show everything you stated and lots more, especially if you complement acticity diagram with some other UML diagrams. In this case I would recommend class diagram, as these data structures are probably important and should also been specified.
Here is a simple example of your situation.
The following diagram is an activity diagram:
It is very intuitive and I guess you will be able to interpret it even without studying UML. Besides this simple sequence flow, you can also model paralel activities, choices (if-then for example), events, responsabiities, etc. You can even "open" the single activities and model then internally with another level of activities.
Those grey elements show the data that is flowing in and out of single actions/activities.
The best thing in UML is combining several diagrams to show different aspects of your problem. Here it is reasonable to somehow explain how the Data A, Data B and other data objects actually look like. In UML there is a diagram for this, a class diagram:
I showed just basic features here. Classes model complex data, are usually equipped with attributes and have realtionshipss of different kinds with other classes. Here you can see how the actial data look like (in contrast to activity, which shows what is done with the data)
Class diagram is one of the structural UML diagrams, while activity diagram is typical behavior diagram. They work best together.
I presume that the sequence diagram would be the best one for your case, because your lifeline would represent your object (or class) and the interaction message between your object would represent your method.
You would also have a chronology with this diagram. This diagram is focus on the interaction from your object.
You can see it : http://en.wikipedia.org/wiki/Sequence_diagram

Diagram Type for Service Connections?

Just wondering what's the correct UML Diagram type to show Service Connection? Essentially saying that "Client A needs a function GetFoo that needs to return items whose quantity is bigger than 20" and "Client B needs a function GetFoo that returns all items"?
A Component Diagram looks correct, but already very concrete in terms of types and very vague in terms of single functions. Composite Structure maybe?
Eventually this is used during planning to decide which functions a service actually needs to have (e.g., an inner GetFoo and two outer GetHeavyFoo/GetAllFoo functions)
I think the composite structure diagram will work for you. However, in my opinion you should combine it with sequence or communication diagram or both - whichever works best for you. I also suggest you check all the uml diagrams and compare them and then decide which ones are best suited for you.
Component diagram is a good solution as well as Sequence.
If you are a beginner in UML you can also just create a class diagram and add a constraints on a method. It would do the job and be easy to understand by the developer team.
It used to be OCL in UML 1.X but now with UML2 direct access to the metamodel you can just create any constraints directly in the model without any transformation. I use EclipseUML Omondo and don't want to use OCL because too complex for a very limited return on investment. My workaround is also better because I can write whatever I want and directly put it inside my class diagram without having two different models (e.g. one for UML and one for OCL).

Resources