Three more options:
Have the User
class contain the supplemental information for both employees and members, with unused fields blank (the ID
of a particular User
would indicate whether the user was an employee, member, both, or whatever).
Have an User
class which contains a reference to an ISupplementalInfo
, where ISupplementalInfo
is inherited by ISupplementalEmployeeInfo
, ISupplementalMemberInfo
, etc. Code which is applicable to all users could work with User
class objects, and code which had a User
reference could get access to a user's supplemental information, but this approach would avoid having to change User
if different combinations of supplemental information are required in future.
As above, but have the User
class contain some kind of collection of ISupplementalInfo
. This approach would have the advantage of facilitating the run-time addition of properties to a user (e.g. because a Member
got hired). When using the previous approach, one would have to define different classes for different combinations of properties; turning a "member" into a "member+customer" would require different code from turning an "employee" into an "employee+customer". The disadvantage of the latter approach is that it would make it harder to guard against redundant or inconsistent attributes (using something like a Dictionary
to hold supplemental information could work, but would seem a little "bulky").
I would tend to favor the second approach, in that it allows for future expansion better than would direct inheritance. Working with a collection of objects rather than a single object might be slightly burdensome, but that approach may be better able than the others to handle changing requirements.