File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Pattern for roles ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Pattern for roles ?" Watch "Pattern for roles ?" New topic
Author

Pattern for roles ?

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

Say I have a Person class.
And I have two roles which I want to model:

  1. Buyer
  2. Seller

  3. 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

Regards,

Pho
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4707
    
    7

Martin Fowler discusses this in his book "Analysis Patterns". You might find some material on his website: http://www.martinfowler.com
Junilu


Junilu - [How to Ask Questions] [How to Answer Questions]
Jes Sie
Ranch Hand

Joined: Jul 24, 2001
Posts: 188
Originally posted by Pho Tek:
Say I have a [b]Person class.
And I have two roles which I want to model:

  1. Buyer
  2. Seller

  3. 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.

------------------
Thank you.
- Simon See
simon-ivy@usa.net
-after office hours-
necro-mani-cide


Thank you.<br /> <br />- Jess Sie<br /> <a href="mailto:jess@see-consulting.com" rel="nofollow">jess@see-consulting.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pattern for roles ?