Search code examples
umlunionmodelinghintconcept

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


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).


Solution

  • 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.