How should User behaviour depending on role be design as POO

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.

May 20, 2025 - 18:30
 0
How should User behaviour depending on role be design as POO

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.

enter image description here