I've got two types of users, both have the same properties but each one will be able to do specific operations. Can I have the same class for both type of users and implement different interfaces for each role or should I use inheritance instead ? For example: class User implements IBuyer and ISeller.
CodePudding user response:
yes you could but, why wouldn't you have two different user classes? Like, class Buyer implement IBuyer and class Seller implement ISeller, I think that would make your code clearer. You could also add a class User with the basic properties they both share, even if they are all of them as you said, which implements an interface called IUser with the shared methods it could have and then your classes Buyer and Seller could inhered from User and have their own separated and independent methods. Anyway, yes, what you commented is possible as well.