Search code examples
umlrelationshipclass-diagram

UML Class Diagram "can be" relationship


I have two classes – Type and Model.

A Type can be primitive, but any Model can be further used as a Type. Hence, a Type can be a Model, but doesn't have to be.

How do I represent this using a UML Class Diagram?

My initial idea is to also define a PrimitiveType and then connect that class and the Model class to the Type using a generalization, but I can't help but assume there is a better way.


Solution

  • One generalization is enough. The arrow should point from Model to Type, which means: a Model is a Type. All Models are Types, but not all Types are Models.

    cd

    By default, a superclass is not abstract, i.e. instances of the superclass may exist. For example, if File is a superclass and Image File and Text File are the only subclasses, then there are three kinds of Files: Images Files, Text Files and Files that are neither Image Files nor Text Files. However, if File is declared as an abstract superclass, then all Files are either Image Files or Text Files.