How should User behaviour depending on role be design as OOP

Imagine I got user which might be either author, administrator, reviewer An author have relation on book that he wrote. An administrator have relation on banned user (we track which administrator have banned a user). A reviewer can make review on book which will be displayed before the other user comments All user can make comments on any books Any user can have multiple roles such as a user can be an author and an administrator, but also a reviewer. I can't design it with inheritance since it would have only one single inheritance class and I need it to be able to have multiple behaviour. Another requirements of course is I don't want to have unnecessary method in my user interface (object). I need some design patterns, some design consideration so I can manipulate properly any user with all of it's behaviour being usable and populated.

May 20, 2025 - 22:00
 0
How should User behaviour depending on role be design as OOP

Imagine I got user which might be either author, administrator, reviewer

  • An author have relation on book that he wrote.
  • An administrator have relation on banned user (we track which administrator have banned a user).
  • A reviewer can make review on book which will be displayed before the other user comments
  • All user can make comments on any books

Any user can have multiple roles such as a user can be an author and an administrator, but also a reviewer.

I can't design it with inheritance since it would have only one single inheritance class and I need it to be able to have multiple behaviour.

Another requirements of course is I don't want to have unnecessary method in my user interface (object). I need some design patterns, some design consideration so I can manipulate properly any user with all of it's behaviour being usable and populated.

enter image description here