Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between a stereotype and a class inheritance in UML?

Tags:

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 
like image 665
James A. Rosen Avatar asked May 06 '09 14:05

James A. Rosen


People also ask

What does stereotype mean in UML?

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.

What is a stereotype class?

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.

What is the purpose of a stereotype in class structuring?

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.

What is inheritance UML?

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.


2 Answers

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.

like image 76
Yarik Avatar answered Oct 25 '22 07:10

Yarik


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.

like image 38
Martin Spamer Avatar answered Oct 25 '22 07:10

Martin Spamer