what is uml stereotype and how to use it
Asked Answered
G

1

7

I'm drawing a class UML for a JAVA software design. I don't really understand what is a stereotype. The formal definition:

The stereotype is a profile class which defines how an existing metaclass may be extended as part of a profile. It enables the use of a platform or domain specific terminology or notation in place of, or in addition to, the ones used for the extended metaclass

Is that mean the stereotype should be the name of the parent class? But why there are some superclasses also has a stereotype?

So for example, I have a superclass Animal and a class dog which extends the Animal class, what could be the stereotype of both classes? Also, why there are some classes without stereotype.

Gemeinschaft answered 7/9, 2020 at 13:35 Comment(0)
A
9

What is a stereotype and what are its purpose?

A stereotype extends UML by allowing to categorize some elements in a more detailed way than foreseen natively by UML. It helps to make the model more expressive.

A typical example are the Entity, Control, and Boundary stereotypes. They are used in a use-case driven design: in a class diagram, you can immediately find-out which classes represents the use-case logic (marked as «control» stereotype), which classes represents user-interface with actors («boundary» stereotype), and which classes represents business/domain objects (marked as «entity»).

Another use of stereotypes is to indicate the way a class is supposed to be implemented, for example to mark as «table» classes that correspond to database tables that are related to in-memory objects, or to indicate among the objects which ones are «persistent». An even more common use is to show some concepts that are language specific and have no equivalent in UML. I think in particular to C# «struct» which have a value semantic wheres C# classes have a reference semantic, or C# «property» (which is a stereotype at attribute level).

How are stereotypes defined?

Sterotypes are defined in a profile. You can see a stereotype as a class in a profile diagram.

But it's not an ordinary class that you could relate to other classes in your model. So there is no inheritance at play here. You would never indicate a superclass as stereotype.

A stereotype is a class related to the "metamodel", which means the UML standard elements defined in the UML standard. So it's a class of classes (or a class of associations, or of any other UML element).

To elaborate on your example, with an abstract superclass Animal and concrete sub-classes Cat and Dog:

  • you could affect them all an «entity» profile, because they all belong to the domain model.
  • if you would want to store the objects in an RDBMS using the concrete table inheritance, you may use a stereotype «persistent» for Cat and Dog (since concrete table inheritance pattern does not implement persistence for the abstract classes)
Alwyn answered 7/9, 2020 at 20:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.