Book a Demo

Author Topic: Associations inherited from superclass?  (Read 7186 times)

pebran

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Associations inherited from superclass?
« on: July 21, 2004, 04:17:04 am »
Do subclasses inherit associations made to the superclass? Does it make a difference whether or not the superclass is abstract? ???

An example:
‘Fruit’ is an abstract class.
The class ‘Fruit’ has two subclasses ‘Banana’ and ‘Strawberry’
The class ‘FruitBowl’ has association ‘contains’ to the class ‘Fruit’

Does this mean that ‘FruitBowl’ contains ‘Banana’ and ‘Strawberry’?
Or do I have to make separate associations to each of Fruits subclasses
« Last Edit: July 21, 2004, 04:17:57 am by pebran »

Andreas_G

  • EA User
  • **
  • Posts: 125
  • Karma: +0/-0
  • And that's the way the cookie crumbles.
    • View Profile
Re: Associations inherited from superclass?
« Reply #1 on: July 21, 2004, 07:39:11 am »
Hi pebran,

inheritance is defined in that way, that subclasses inherit all properties of your base class.

In your case it's enough to have an association to your class 'Fruit'.
That means that 'FruitBowl' can contain all kinds of Fruits. The problem is, that you don't know the exact type of your fruits in 'FruitBowl'. But that is an other story.

If you create a seperate acossiation to each of your subclasses, that means your 'FruitBowl' class has a seperate attribute for each subclass. If you create a new kind of 'Fruit', you have also to change the class 'FruitBowl'. And I'm sure, that's not that what you want to have.

bye
Andreas
bye
Andreas

pebran

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Associations inherited from superclass?
« Reply #2 on: July 21, 2004, 12:51:07 pm »
Hi Andreas

Well, I did knew that a subclass inherits the properties of the superclass. Just didn't knew that associations should be seen as properties.

Thanks,
Peter

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: Associations inherited from superclass?
« Reply #3 on: July 21, 2004, 04:43:06 pm »
Just consider what the association means in a concrete sense and you will see why it is inherited.
B
"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.