UML - How to model either/or/both (union) concept?
Asked Answered
A

2

4

In my business we have a "Data Store" where data is stored (e.g. database, flat file, etc) and a "Data Provider" who delivers the data (e.g. human, sensor, etc).

To model this in UML is no problem for me. BUT, sometimes "instances" are both, a data store and a data provider (e.g. an IoT device). How can I model this?

"An instance can be a data store or a data provider or both".

A data store and data provider have different properties, an instance that is both (a data store and a data provider) should have both properties.

I looked for multiple inheritance or a union concept in UML but did not find the right concept. Can anyone give me a hint how to model this? :-)

EDIT: My primary goal is to develop a conceptual model (not for implementation).

Autoradiograph answered 1/1, 2020 at 18:2 Comment(1)
This is a refreshingly good UML question for Stack Overflow!Jeffry
J
3

To make something both a "Data Store" and a "Data Provider", you have two choices. The first choice is to multiply classify an instance. The second choice is to instantiate a class that specializes both classes. For either choice, the "Data Store" and "Data Provider" classes must not be disjoint [1].

For the first choice, a UML Instance Specification allows multiple classifiers, which allows you to mix and match classes. If you create an Instance Specification and classify it with both "Data Store" and "Data Provider", you get the effect you are looking for.

For the second choice, UML allows a class to specialize multiple other classes, which allows you to create a subclass of the intersection of those other classes [2]. If you create a class called "Data Store Provider" and use a Generalization arrow to connect it both to "Data Store" and to "Data Provider", you can also get the effect you are looking for.


[1] In UML, you make classes disjoint using a Generalization Set that has the meta-property isDisjoint=true. Don't do that for either of these choices.

[2] In UML, there is no way to express the exact intersection, and most people don't understand why you would want to do that anyway. A plug-in for MagicDraw, called the Cameo Concept Modeler, extends UML so that you can express this, among other things that UML cannot express, so you can model ontologies.

Jeffry answered 1/1, 2020 at 20:1 Comment(2)
Thank you for your answer! I modeled it in the following way: imgur.com/Kvka0cb (Try to use the approach " If you create a class called "Data Store Provider" and use a Generalization arrow to connect it both to "Data Store" and to "Data Provider") Is this correct? I am not sure if it is allowed to use both, a generalization and an assertion between "data provider" and "data store provider".Autoradiograph
There are many things in that diagram to nitpick about, but you have the general idea. You should consider asking a new question to get feedback because comments aren’t the right place to practice.Jeffry
L
2

I might have to think a bit more over this, but one way that comes to mind is to use different (optional) ports that realize different interfaces:

enter image description here

Leukoderma answered 1/1, 2020 at 18:29 Comment(2)
Thank you very much! May I have forgotten to mention that my primary goal is making a conceptual model that will not be implemented. Nevertheless, I will think about using Interfaces... thank you!Autoradiograph
It depends on what you think a concept is. The above (to me) is just a concept :-) Even on a conceptual level you may have ports and interfaces.Leukoderma

© 2022 - 2024 — McMap. All rights reserved.