Peter P.
Peter P.

Reputation: 141

Proper UML modelling for inheritance from an abstract class

Which one ist the correct model for the following implementation.

class Habitat {
    int id;
    String name;
}

abstract class Animal {
    int id;
    String name;
    Habitat habitat;
}

class Fish extends Animal {
    // Fish Attributes
}

two class diagrams with Habitat, Animal and Fish

Upvotes: 2

Views: 429

Answers (1)

qwerty_so
qwerty_so

Reputation: 36305

Both would be correct from an implementational view. However, since the Habitat is defined as a property of Animal the top left would be the proper model. The bottom right one would show the inherited association rather than the general one. This would be some special view of the model. Diagrams are always a certain view of the model and (almost) never the full picture of it.

Rather than using a named property you should put a role name along the association and use the dot notation to make it an owned property.

The navigation is just superfluous.

Upvotes: 2

Related Questions