BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to model relationships?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design
View previous topic :: View next topic  
Author Message
Robert Cram
Guest





PostPosted: Wed Dec 01, 2004 9:15 am    Post subject: How to model relationships? Reply with quote



Hi All,

I'm trying to model (real life) relationships. In this case a person
(class PERSON) can have 0..n relationships (class RELATIONSHIP) over
time with 0..1 partners (class PERSON). I can't think of a way to model
this in UML. Any thoughts on how to model the associations between the
two classes PERSON and RELATIONSHIP in a class diagram?

TIA,
Robert.
Back to top
Robert Cram
Guest





PostPosted: Wed Dec 01, 2004 9:58 am    Post subject: Re: How to model relationships? Reply with quote



Joanna Carter (TeamB) wrote:

Quote:
"Robert Cram" <rcram (AT) knoware (DOT) nl> a icrit dans le message de news:
41ad99d1$1 (AT) newsgroups (DOT) borland.com...

I'm trying to model (real life) relationships. In this case a person
(class PERSON) can have 0..n relationships (class RELATIONSHIP) over
time with 0..1 partners (class PERSON). I can't think of a way to
model this in UML. Any thoughts on how to model the associations
between the two classes PERSON and RELATIONSHIP in a class diagram?

This is known as an 'association class' and is drawn as a loop
from/to the person class with a dotted line from that loop to the
relationship class.

Joanna


Hi Joanna,

I think in this case it's not an association class because it's
possible for example that a person is married to the same person twice,
so the class RELATIONSHIP must have it's own identity.

Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Wed Dec 01, 2004 10:35 am    Post subject: Re: How to model relationships? Reply with quote



"Robert Cram" <rcram (AT) knoware (DOT) nl> a écrit dans le message de news:
41ad99d1$1 (AT) newsgroups (DOT) borland.com...

Quote:
I'm trying to model (real life) relationships. In this case a person
(class PERSON) can have 0..n relationships (class RELATIONSHIP) over
time with 0..1 partners (class PERSON). I can't think of a way to model
this in UML. Any thoughts on how to model the associations between the
two classes PERSON and RELATIONSHIP in a class diagram?

This is known as an 'association class' and is drawn as a loop from/to the
person class with a dotted line from that loop to the relationship class.

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Robert Cram
Guest





PostPosted: Wed Dec 01, 2004 10:41 am    Post subject: Re: How to model relationships? Reply with quote

Jim Cooper wrote:

Quote:

I think in this case it's not an association class because it's
possible for example that a person is married to the same person
twice, so the class RELATIONSHIP must have it's own identity.

That's what Joanna is saying :-)


Cheers,
Jim Cooper



Now I'm confused...

I thought the essence of an association class is that it does NOT have
its own identity. It gets its identity from the two objects that are
associated (the assocation class models properties of the association).
In this case the RELATIONSHIP class must have it's own identity (and
therefore cannot be an association class) because the properties of the
relationship are NOT the properties of an association between two
persons (the same two persons can have more relationships over time).

Back to top
Jim Cooper
Guest





PostPosted: Wed Dec 01, 2004 11:07 am    Post subject: Re: How to model relationships? Reply with quote


Quote:
I think in this case it's not an association class because it's
possible for example that a person is married to the same person twice,
so the class RELATIONSHIP must have it's own identity.

That's what Joanna is saying :-)


Cheers,
Jim Cooper

_______________________________________________

Jim Cooper [email]jim (AT) falafelsoft (DOT) com[/email]
Falafel Software http://www.falafelsoft.com
_______________________________________________

Back to top
Robert Cram
Guest





PostPosted: Wed Dec 01, 2004 12:10 pm    Post subject: Re: How to model relationships? Reply with quote

Joanna Carter (TeamB) wrote:

Quote:
"Robert Cram" <rcram (AT) knoware (DOT) nl> a icrit dans le message de news:
[email]xn0dqhuy417kuab000 (AT) forums (DOT) borland.com[/email]...

I thought the essence of an association class is that it does NOT
have its own identity. It gets its identity from the two objects
that are associated (the assocation class models properties of the
association). In this case the RELATIONSHIP class must have it's
own identity (and therefore cannot be an association class) because
the properties of the relationship are NOT the properties of an
association between two persons (the same two persons can have more
relationships over time).

On the contrary, an association class should have its own identity,
otherwise it has no relevance to the association.

In the scenario of a relationship between two different classes, you
would typically have :

Member -- Attendance -- Meeting

Each Attendance records which member attended which meeting, thus
resolving what is essentially a many to many relationship.

This is exactly what you have with the possible relationships between
many people.

Joanna



Hi Joanna,

Perhaps it's a question of terminology. Let me try to explain my view:

In your example attendance gets its identity from the combined identity
of a certain member and a certain meeting. That's why it's an
association class. There is always one attendance for one
member/meeting combination.

This is not true for relationships. There can be more relationships for
one person/person combination (married twice to the same person),
that's why it needs its own identity and can't be an associationclass.

Am I making sense?



Back to top
Robert Cram
Guest





PostPosted: Wed Dec 01, 2004 12:23 pm    Post subject: Re: How to model relationships? Reply with quote

Bob Dawson wrote:

Quote:
"Robert Cram" wrote

I thought the essence of an association class is that it does NOT
have its own identity.

From the RDBMS point of view, a row in a simple association table is
uniquely identifiable from its composite key, and so needs no further
identification. To allow for repetitious relationships, the DBA might
fall back on a dumb key, but even then would look for some other
tracked characteristice that provides uniqueness when added to the
composite key--for example StartDate (you can marry and remarry the
same person, but not at the same time). At that point the DBA is
likely to stop regarding the table as a simple association any regard
it instead as a true entity table.

But from an OO point of view everything has an id, whether
theoretically needed by the DBA or not.

bobD

Hi Bob,

Ok, I understand that. I probably didn't use the right terminology by
saying an asociationclass doesn't have an identity. I should have said:
"an association class takes its identity from from the object
references in it" (shamelessly copied from the UML reference manual)

For relationships this is not the case. So in my view it can't be
modelled as an association class.




Back to top
Robert Cram
Guest





PostPosted: Wed Dec 01, 2004 12:29 pm    Post subject: Re: How to model relationships? Reply with quote

Bjxrge Sfther wrote:

Quote:
Robert Cram wrote:
I'm trying to model (real life) relationships. In this case a person
(class PERSON) can have 0..n relationships (class RELATIONSHIP) over
time with 0..1 partners (class PERSON).

This design solution does have pitfalls...the "0..1" constraint being
the most apparent case for a modification....Wink

I wonder: is being single having a relationship with no one, having a
relationship with oneself or not having a relationship at all? The real
world is overly complicated ;)

Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Wed Dec 01, 2004 12:58 pm    Post subject: Re: How to model relationships? Reply with quote

"Robert Cram" <rcram (AT) knoware (DOT) nl> a écrit dans le message de news:
[email]xn0dqhuy417kuab000 (AT) forums (DOT) borland.com[/email]...

Quote:
I thought the essence of an association class is that it does NOT have
its own identity. It gets its identity from the two objects that are
associated (the assocation class models properties of the association).
In this case the RELATIONSHIP class must have it's own identity (and
therefore cannot be an association class) because the properties of the
relationship are NOT the properties of an association between two
persons (the same two persons can have more relationships over time).

On the contrary, an association class should have its own identity,
otherwise it has no relevance to the association.

In the scenario of a relationship between two different classes, you would
typically have :

Member -- Attendance -- Meeting

Each Attendance records which member attended which meeting, thus resolving
what is essentially a many to many relationship.

This is exactly what you have with the possible relationships between many
people.

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Bob Dawson
Guest





PostPosted: Wed Dec 01, 2004 1:09 pm    Post subject: Re: How to model relationships? Reply with quote

"Robert Cram" wrote
Quote:

I thought the essence of an association class is that it does NOT
have its own identity.

From the RDBMS point of view, a row in a simple association table is
uniquely identifiable from its composite key, and so needs no further
identification. To allow for repetitious relationships, the DBA might fall
back on a dumb key, but even then would look for some other tracked
characteristice that provides uniqueness when added to the composite
key--for example StartDate (you can marry and remarry the same person, but
not at the same time). At that point the DBA is likely to stop regarding the
table as a simple association any regard it instead as a true entity table.

But from an OO point of view everything has an id, whether theoretically
needed by the DBA or not.

bobD



Back to top
Robert Cram
Guest





PostPosted: Wed Dec 01, 2004 1:38 pm    Post subject: Re: How to model relationships? Reply with quote

Jim Cooper wrote:

Quote:

In your example attendance gets its identity from the combined
identity of a certain member and a certain meeting.

Why? In Joanna's example it's true you wouldn't expect to have the
same member attending a given meeting more than once, but that does
not imply anything about identity. Typically objects have some other
means of identification, eg memory address or a specific property
(like OID)

Cheers,
Jim Cooper


Hi Jim,

I guess my use of the word "identity" has complicated things. The UML
language reference manual probably states it more clearly:

"An association class connecting classes A and B is not the same as a
class D with binary associations to A and B. Like all links, a link of
an association class such as C takes its identity from the object
references in it. The attribute values are not involved in providing
identity. Therefore, two links of C must not have the same pair (a,b)
objects, even if their attribute values differ, because they would have
the same identity. That is, given attribute E, it is not permitted that
(a,b,e1) and (a,b,e2) both be instances of C, because they share the
same identity (a,b)"

"An association, including an association class such as C , is a set of
tuples and has no duplicates among its object references; whereas, an
implicit relationship such as D is more like a bag , which can have
duplicates"

That's why I concluded that the class RELATIONSHIP cannot be modelled
as an association class. If I'm wrong, I'm at least in good company ;)

Back to top
Joanna Carter (TeamB)
Guest





PostPosted: Wed Dec 01, 2004 1:44 pm    Post subject: Re: How to model relationships? Reply with quote

"Robert Cram" <rcram (AT) knoware (DOT) nl> a écrit dans le message de news:
[email]xn0dqhxq21bb6l3003 (AT) forums (DOT) borland.com[/email]...

Quote:
Ok, I understand that. I probably didn't use the right terminology by
saying an asociationclass doesn't have an identity. I should have said:
"an association class takes its identity from from the object
references in it" (shamelessly copied from the UML reference manual)

For relationships this is not the case. So in my view it can't be
modelled as an association class.

There is no reason why an association class cannot have its own identity as
well as holding the ids of its references. The UML docs are not intended to
be rules set instone, they are guidance.

Many good structures used in OO are not mentioned in the UML docs, see the
Design Pätterns material available.

If you insist on creating a 'key' out of the association then to make it
unique, you would have to also include the start/end dates of the
relationship; thus more fully describing the relationship.

If an association class is nothing more than a pair (or more) of keys, then
I would say that you are looking more at the RDBMS idea of resolving n-n
relationships without adding the extra data that makes it a true association
class.

Joanna

--
Joanna Carter (TeamB)

Consultant Software Engineer
TeamBUG support for UK-BUG
TeamMM support for ModelMaker



Back to top
Robert Cram
Guest





PostPosted: Wed Dec 01, 2004 2:05 pm    Post subject: Re: How to model relationships? Reply with quote

Bob Dawson wrote:

Quote:
"Robert Cram" wrote

"an association class takes its identity from from the object
references in it" (shamelessly copied from the UML reference manual)

Okay--from that point of view the relevant discussion is the
"association class" entry in the 'Encyclopedia of Terms', UML
Reference Manual (in my copy pp 157-9). See the last paragraph of the
Discussion section and figure 13-28, 'Reified association.'

Basically the three amigos model a reified association class as a
normal class, so instead of putting it on a dotted line hanging off
the primary association solid line, the association class appears
directly on the solid line as an intermediary, reducing the
multiplicity markings accordingly:

E1|1_____*|AssociationClass|*_________1|E2|

Or in your case

Person |1_____*| Relationship |
|1_____*| |

Then there are a lot of complications that require either OCL or some
other annotation, as
--A relationship is non-reflexive (people generally don't marry
themselves) --some types of relationships may be multiplicitous only
over time (only one spouse at a time, depending on jurisdiction)
--some types of relationships may be assymetric (spouse must be of
opposite sex), again depending on jurisdiction
--some types of relationships may be incompatible with relationships
with the same person (a person might have both a spousal and an
illicit lover relationship, but not with the same person)

bobD


Thanks Bob,

I live in Holland, so thankfully some complications do not apply ;)

One of my remaing problems is how to make explicit in this model that
if A has a relationship to B, B has the same relationship with A.


Back to top
Robert Cram
Guest





PostPosted: Wed Dec 01, 2004 2:07 pm    Post subject: Re: How to model relationships? Reply with quote

Bob Dawson wrote:

Quote:
"Robert Cram" wrote

I wonder: is being single having a relationship with no one,
having a relationship with oneself or not having a relationship
at all?

Best to remember at this point that the goal of the model is not to
model the real world, but only to produce a model accurate enough to
function for those aspects relevant to the problem. So the answer
really is 'depends on what the program is trying to do.'

The real world is overly complicated ;)

Indeed. So the real question is not 'is this model right?', but
rather 'will this model work for the task at hand?' Trying to model
'accurately' rather than 'appropriately' is a mistake.

bobD

Hi Bob,

I know, this post was "in jest", as was (i hope) the post I replied to
;)

Robert.






Back to top
Jim Cooper
Guest





PostPosted: Wed Dec 01, 2004 2:17 pm    Post subject: Re: How to model relationships? Reply with quote


Quote:
In your example attendance gets its identity from the combined identity
of a certain member and a certain meeting.

Why? In Joanna's example it's true you wouldn't expect to have the same
member attending a given meeting more than once, but that does not imply
anything about identity. Typically objects have some other means of
identification, eg memory address or a specific property (like OID)

Cheers,
Jim Cooper

_______________________________________________

Jim Cooper [email]jim (AT) falafelsoft (DOT) com[/email]
Falafel Software http://www.falafelsoft.com
_______________________________________________

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OO design All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.