Book a Demo

Author Topic: Super and subclasses - and associations  (Read 9505 times)

pebran

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Super and subclasses - and associations
« on: January 23, 2005, 03:53:29 am »
My scenario is like this:
I have a class ’Super’ that has subclasses ‘SubA’, ‘SubB’, ‘SubC’, etc.
If I let Super have two associations to a class ‘Relation’ does this inherit to the subclasses in a way that makes it possible to describe that each subclass is interconnected through ‘Relation’?

In other words, will it give me this desciption:
  SubA ---- Relation ---- SubB
  SubA ---- Relation ---- SubC
  SubB ---- Relation ---- SubC

Thanks,
Peter
« Last Edit: January 23, 2005, 11:32:44 am by pebran »

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Super and subclasses - and associations
« Reply #1 on: January 23, 2005, 02:26:06 pm »
 :) I think that if you would provide a slightly more concrete example  we may be able to provide more help.  I cannot see really what it is that you are trying to show.
bruce
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

pebran

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Super and subclasses - and associations
« Reply #2 on: January 24, 2005, 11:44:33 am »
I’ll try to explain.
I have a class ‘Contact’ with subclasses ‘Person’, Group’ ‘Organization’ and ‘OrganizationUnit’.
Between each pair of subclasses, ie. Group—Organization , there exists an association class ‘Role’.
These associations /association classes could of course be model individually but I need to model this in a way that ensures that I can add new subclasses to ‘Contact’ and at the same time get all the associations between the new class and the existing ones.
As I understand it a reflexive association (with or without attached class) on Contact will be inherited as just that – as a reflexive association on Person, a reflexive association on Group, etc. In other words it won’t get me the associations I need between the subclasses.
That is why I now need to know if I can create two associations between Contact and Role and thereby create associations between each subclass.
Hope that made it clearer

Regards,
Peter Bruhn Andersen

TrtnJohn

  • EA User
  • **
  • Posts: 176
  • Karma: +0/-0
    • View Profile
Re: Super and subclasses - and associations
« Reply #3 on: January 24, 2005, 12:05:56 pm »
I am still a bit confused are you trying to say.  Is this the relationships you are trying to describe?

Each Contact has a Role (Association)
Each Person is a Contact (Generalization)
Each Group is a Contact (Generalization)
Each Organization is a Contact (Generalization)
Each OrganizationUnit is a Contact (Generalization)

What other relations do you need to show?  If a Person is a Contact and a Contact has a Role there isn't any need for any other associations.  Generalize means that Person inherits everything that Contact has.  

pebran

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Super and subclasses - and associations
« Reply #4 on: January 24, 2005, 01:36:05 pm »
Yes and no. Person, Group, Organization and OrganizationUnit does of course all have Contact as a generalization. But there is more to it.
May if you think of this as having Role as the center piece. Role has TWO associations to Contact. That implies that Role has two associations to any of Contact’s subclasses. But does it also imply that each association could be with different subclasses of Contact. As an example:
Role has one association to Person and one association to Organization.
And similar examples could be made with the other subclasses.
THAT is what I want to achieve. Any way to do that apart from doing it specifically for each combination of subclasses?

Regards,
Peter Bruhn Andersen

TrtnJohn

  • EA User
  • **
  • Posts: 176
  • Karma: +0/-0
    • View Profile
Re: Super and subclasses - and associations
« Reply #5 on: January 24, 2005, 02:05:38 pm »
From your example, I am not sure what you mean by the Role class.  I am having a hard time picturing your  Role has 2 Contacts association.  Why would that exist?

In this case, each subclass of Contact would have no automatic association to Role.   You would have to do this per sub-class.  But, something doesn't sound right because this type of relationship sounds like it should be inherited, as per my example.

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Super and subclasses - and associations
« Reply #6 on: January 24, 2005, 02:46:08 pm »
Quote
But does it also imply that each association could be with different subclasses of Contact.


No, it implies that anything that is instantiated as a specialisation of Contact has two associations inherited from Contact to a set of objects instantiated as instances of Roles (depending on the multipicities on the two Contact-Role associations).

By way of example,  a (specific) Person, let's call him "Bruce", is an instance of a Contact  - and therefore inherits all the attributes of a Contact, including the two associations with  some as yet uninstantiated Role objects.  Now quickly, create another set of objects:
Person p2=new Person("Peter");
Person p3=new Person("John");
Person p4=new Person("thomaskillan");
Organization o1=new Organization("Saperion");
Group g1=new Group("EAForum:);

Now, lets start instantiating some Roles (given that the constructor for Role is Role(Contact sourcecontact, Contact targetcontact, string roletype);


Role r1=new Role(p2, g1, "asks");  // Peter asks the EAForum

Role r2 = new Role(p1,p2, "doesn't understand') // Bruce doesn't understand Peter('s question)

Role r3 =  new Role(p3,p2, "understands") // John understands Peter

Role r4 = new Role(p4, o1, "works at"); // thomaskillen works at Saperion

Finally, create the associations for the Contacts, viz:
(nb the way I am thinking, the Contact source and target attributes are collections)

p2.source.add(r1) // Peter acts as the source contact in r1
g1.target.add(r1) // EAForum is a target in r1
p2.target.add(r2) // Peter is a target in r2

etc etc ...

(Now, you wouldn't implement this is such a stepwise manner, I only did it to show how the relationships are creatable regardless of the spercialization types)

hth
Bruce

p.s. by way of summary - anything that is a Contact can be involved in any number of relationships with any other things that are contacts - either as the source in the role or as the target in the role.
« Last Edit: January 24, 2005, 02:57:58 pm by sargasso »
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

TrtnJohn

  • EA User
  • **
  • Posts: 176
  • Karma: +0/-0
    • View Profile
Re: Super and subclasses - and associations
« Reply #7 on: January 24, 2005, 04:45:08 pm »
Fixed:

Role r3 =  new Role(p3,NULL, "understands")    :P

Bruce,

Would you use 2 bi-directional associations between Contact and Role to model what you describe?

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Super and subclasses - and associations
« Reply #8 on: January 24, 2005, 05:01:00 pm »
Yes.
b

On second thought ... yes, if I have got the gist of what Peter is trying to do.

I have presumed that he wants to be able to go both ways as the exact characterisation of the role is not known until the relationship between the subtypes is populated and that there is an unknown number of subtypes - therefore an unknown number of relationship types.  Having dealt with this type of thing before, I've actually found it easier to build the bidirectional solution than a unidirectional solution.  The time we made it unidirectional 80% of the functionality was fine and 20% was impossible.....  
« Last Edit: January 24, 2005, 09:37:01 pm by sargasso »
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.