0

I have three classes-User, Vendor, and Customer. Now Customer 'is-a' User and have same attributes as User has, so it should inherit User class. But the confusion is in case of Vendor. A Vendor 'is-not-a' User according to business rule as a vendor is not supposed to use the application, but it also has the same attributes the User has. Should Vendor be inherited from a User class in this particular case or not?

2
  • If Vendor has every attribute that User does yet it does not use the application, then there's something about User that you haven't captured yet. Commented Jul 19, 2015 at 2:34
  • I suggest reading upon design patterns. Design patterns won't answer your question directly but will help you understand common design (how to organize your classes) related problems/solutions in oop. Commented Jul 19, 2015 at 2:43

2 Answers 2

1

Logically, I'd say no. If I were designing such a system, I'd envision a User object having methods such as Login, ChangePassword, GetLastLoginDate, etc. On the other hand a Vendor might have methods such as AddProduct, ReceivePurchaseOrder, etc.

Just because it has attributes such as First Name and Last Name and other such variables doesn't make it a user. An object is more than just properties, it also includes the actions (methods). I would assume the methods that would be part of a User class would be very different than a Vendor based on what I know of both users of an application and vendors. If Vendors were a type of user that logged into your application, but had different access than Customers, then I'd say yes. However, based on your description they are very different things.

Sign up to request clarification or add additional context in comments.

Comments

1

There are two ways to approach this:

1) Have both User and Vendor inherit from the same parent object, maybe Account. Account contains the attributes common to User and Vendor, and will allow you to later add specialized attributes to Users that Vendors don't get.

2) If the attributes of Vendor will always match the attributes of User, you could add a "Can Log In" attribute to User and have Vendor inherit from it. This would be less complex in the short term but could cause problems later if User and Vendor diverge.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.