umlentity-relationshipclass-diagram

When to use specializations?


I know that specializations should only be used if the created specializations have distinctive elements such as attributes or their own associations. if these are missing how could they be modeled? I had thought of them as simple string attributes or if they have a limited range of value with an enumeration. Are there other ways to represent them? if I have a class C1 with an optional association with another class C2, if I specialize C1 in different subclasses but without attributes and associations but one of these due to a particular constraint can be associated with C2 only in a particular case it is always wrong to represent them as specializations ?


Solution

  • Classes are not only about attributes and associations. It's also about behavior, (operations, signal reception) and constraints. Specialization does not require any discrimination in UML.

    It can therefore be perfectly meaningful to have a specializing class that does not add any attribute or association. So there is no right or wrong in this regard. It's about more or less suitable for a particular need.

    While it is not well known either, in UML the class of an object can even change dynamically (though, this kind of modelling should be used with care as it proves difficult or impossible to implement in many programming languages).