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?
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.
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.