Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm starting work on a new personal project and I'm looking to get advice in regards to setting up my classes.

My base class is a User. The User class will have the following general properties

  • User ID
  • User Name
  • Password
  • Address (this will be a complex/value type)

I will then have a Subscriber class which is a User who has chosen to subscribe to a plan that I offer. The Subscriber class will have its own properties in addition to that of the User including:

  • Subscriber ID
  • Plan ID
  • Date Subscribed
  • etc

Is inheritance the way to go here with User being the base class or is a foreign key from the Subscriber to User class the better way? If inheritance is preferred then which method? TPH or TPT?

The plan is to have other classes with the User class acting as the base including Participants and Volunteers.

Thanks!

share|improve this question

1 Answer 1

up vote 2 down vote accepted

My first thought, along the lines of 'prefer composition to inheritance', is that inheritance isn't needed (nor the best representation of the common 'subscriber' system), and that your User class should have a collection of Subscriptions.

The Subscriptions would be basically the same as you've described them, but without the inheritance piece. A particular Plan's 'Subscribers' would be the collection of Users that have a Subscription to the Plan.

Likewise with Participants and Volunteers.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.