This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Originally posted by Pho Tek: Say I have a [b]Person class. And I have two roles which I want to model:
How do you implement this ? I've tried using interfaces. e.g.
The problem I see here is that I can't changed my role dynamically. For example, the program might allow a Person to assume another role in the middle of the program. Thanks Pho[/B]
This maybe a late reply, but, heh, it's better never. OK, maybe you can try like this: - Person has a "1 to 0..*" composition relationship with PersonRole. Place a Condition on the relationship like "Max 1 each". PersonRole is an abstract class. Both Buyer and Seller inherits from PersonRole. This way, Person can have zero or a max of either Buyer or Seller role.