I'm confused about the difference between something being a "stereotype" and being a "superclass" in UML.
Let's say I want to create a diagram involving a "WidgetMaker
." WidgetMaker
is clearly an Actor
so the UML standard is to stereotype it actor:
<<Actor>> WidgetMaker
But I grew up programming in the Java/Ruby/C++ world. In that world, the relationship is:
class Actor end class WidgetMaker < Actor end
That looks like this in UML:
Actor ^ | WidgetMaker
So my question is: why does UML have stereotypes at all when you can just as easily model those concepts using class inheritance, which it also has.
Once we have more "kinds" of actors, the question becomes even murkier:
Actor ^ | ------------------------ | | | Person Robot Group ^ | WidgetMaker
versus
<<Actor>> <<Person>> WidgetMaker
In UML models, a stereotype is a model element that identifies the purpose of other model elements. UML 2.1 provides a standard set of stereotypes that you can apply to model elements. You can use a stereotype to refine the meaning of a model element.
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.
Stereotypes is extensibility mechanisms in UML which allows designers to extend the vocabulary of UML in order to create new model elements. By applying appropriate stereotypes in your model you can make the specification model comprehensible. A stereotyped model type can appear in a project many times.
Inheritance. A very important concept in object-oriented design, inheritance, refers to the ability of one class (child class) to inherit the identical functionality of another class (super class), and then add new functionality of its own.
As far as I understand, the primary purpose of stereotypes is to enable extension of UML itself (as a modeling language), and not to model anything.
Having said that, I also think that your question implies another possible valid answer: some people prefer to use stereotypes to designate (informally!) certain commonalities between classes. They might do that just because it is easier than subclassing and "good enough" for the purposes of their models.
For example, many software systems have classes that represent so called domain entities (things like companies, customers, purchase orders, products, etc.). Eventually, you might want to have a common class like Entity
to derive Company
, Customer
etc. from. But initially it is likely to be sufficient just to use stereotyped classes like these <<Entity>> Company
, <<Entity>> Customer
etc. Essentially, it's just a matter of convenience (and cost/benefit!) of your modeling efforts.
In your example Actor probably doesn't need to be implemented as a class, but this may or not always be the case. Stereotype are abstractions that can be applied to most UML elements not just classes.
They encapsulate semantics without implying how those semantics will provided. Another example could be a communications channel stereotyped as HTTP or RPC. They are communicating with the reader how something will be provided without complicating the model with unnecessary detail.
The UML specification provides a number of predefined stereotype, but their real power comes from being able to define your own through profiles. You might label a domain object as an EJB to save yourself specifying all the boiler plate code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With