There is a design issue I need your help with.
Suppose I need to design a clothing store. In this store there are Sellers and Buyers each one is registered in the shop with an ID.
We want to allow a Seller to sign in as a Buyer and vice versa (using the same ID he was originally signed up with).
Keep in mind that Buyer and Seller have different data memeber and also in order to use the function Buy all we need is the Buyer data member and not he Seller data member.
At first sight, while considering that the Seller has different data member from the Buyer I decided to set these two classes as derived of ShopPerson which is derived from Person.
The reason I decided to have ShopPerson class is to allow Buyer and Seller a base class containing common functions .( becuase both of them can Buy and Sell)
My problem is:
The “Buy” function should be only member of Buyer, but then how could I treat a Seller as a Buyer? If by chance the Buyer is a Seller than he won’t have this function.
My solution above, using a ShopPerson class to have a shared/common classes isn’t good either because the Buy function uses some data member which are only dedicated for the Buyer and the ShopPerson wouldn’t be familiar with them.
The only solution I have in mind is to drop of inheritance, but I am not sure if this is correct.
How can I solve this design issue? Any ideas?
Thank you all, Syndicator!
Inheritance may not be what you need. Perhaps something like the below.
i.e You have a central list of
ShopPerson, butBuyerandSellerare thin classes which are instantiated on a transaction by transaction basis. You could use inheritance nowAnd inherit
BuyerandSellerfrom this class.