Home > Software engineering >  Can behavior of subclasses vary according to traditional modeling?
Can behavior of subclasses vary according to traditional modeling?

Time:11-29

I developed a class diagram, where I'm not sure if I understood the role of superclasses.

In my diagram, user is a superclass, but I still have different roles of users that have different behavior. Is it allowed to override behavior of subclasses or is that fundamentally wrong?

Is there a better design for this case?

enter image description here

CodePudding user response:

Yes, a subclass can redefine/override the behavior of a superclass. So Blocked user, Normal user and Moderator user could each override some behavior of User and add their own behavior on top.

enter image description here

Unrelated hint: when you consider to redefine behavior of a subclass, it's sound practice to design according to the Liskov Substitution Principle as much as possible.

  • Related