I have a basic User model that satisfies all the needs of a generic user. I now need to create several different roles for the user, each with about 10-20 different methods that are unusable by the other roles.
Assume that I have to load the generic User class to determine the user’s role…
Since it’s inefficient and heavy to package so many different role-based methods into the generic User model (when they can’t be utilized by all roles), what is the best way to give user’s access to their role-based methods ONLY when they need them?
Here are some ideas I’m tossing around:
-
Have a separate class of services per role, and give them to the User class according to the user’s role
-
Simply lug around all the methods in the user class, and only allow access to each when the user has the correct role.
-
Totally refactor and make the role based classes inherit from the User class.
Are any of these good ideas, or is there a better idea at all?
Why not just composition the role based classes into the User object?