3-ary relationship and association class
From: Ishan De Silva (idesilva_at_eudoramail.com)
Date: 09/06/04
- Next message: Ishan De Silva: "Re: Object-orientation: Have I finally attained "high priesthood"?"
- Previous message: Universe: "Re: Database type independence"
- Next in thread: H. S. Lahman: "Re: 3-ary relationship and association class"
- Reply: H. S. Lahman: "Re: 3-ary relationship and association class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Sep 2004 22:11:22 -0700
Hi,
The following scenario is from a trading system domain.
There are "Users" who trade in various "Instruments". They play
different "Roles" for these instruments and the role depends on the
instrument. These users are members of different firms.
So we have:
[Firm] [Role]
| |
| |
[User]-------------<>-------------[Instrument]
|
|
|
[Privileges] <- association class
If we take,
class User
{
public:
bool HasPrivilege(int action, Instrument* i);
private:
map<Instrument*, Role*> itsInstruments;
};
Is it a correct implementation of the 3-ary relationship? Is this what
you call "reification"? Does this container(map) represent the
association class?
There is another scenario where the users get their instruments via
the firm.
Users are members of a firm. They have a particular role. The
instruments are attached to the firm. Users are allowed to trade in
their firm's instruments.
[Firm]---------[Instrument]
|
|
[User]----------[Role]
* 1
The idea is to modify the User class as follows to handle the above
scenario.
class User
{
public:
bool HasPrivilege(int action, Instrument* i);
private:
int type;
map<Instrument*, Role*> itsInstruments;
Firm* firm;
Role* role;
};
bool User::HasPrivilege(...)
{
if(first type)
{
// Use map to check privilege
}
else
{
// Use firm and role to check privilege
}
}
During the past few weeks, I have been trying hard to come up with a
more elegant approach to handle both scenarios. Appreciate any
suggestions to improve this design.
Thanks,
Ishan.
- Next message: Ishan De Silva: "Re: Object-orientation: Have I finally attained "high priesthood"?"
- Previous message: Universe: "Re: Database type independence"
- Next in thread: H. S. Lahman: "Re: 3-ary relationship and association class"
- Reply: H. S. Lahman: "Re: 3-ary relationship and association class"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]