jGuru Forums

Aggregation or Multiplicity?
2 posts in topic
Flat View
TOPIC ACTIONS:

Posted By:   Cyrus_Anastasakis
Posted On:   Tuesday, March 30, 2004 03:48 AM

Hello. I have a rather simple question. I want to model for example a house with rooms. Should I use a model like the following? 1..* House -------------> Room I think the correct way is to use aggregation (or composition). Like: 1..1 1..* House----->Rooms <>-------->Room When would we go for the first design? Are there any particular advantages/disadvantages for each design? Thanks in advance for any comments!    More>>

Hello. I have a rather simple question.

I want to model for example a house with rooms.

Should I use a model like the following?

```

1..*

House -------------> Room

```

I think the correct way is to use aggregation (or composition).

Like:

```
1..1           1..*

House----->Rooms
<>-------->Room

```

When would we go for the first design?
Are there any particular advantages/disadvantages for each design?

Thanks in advance for any comments!

<<Less

Re: Aggregation or Multiplicity?

Posted By:   Diwakar_R
Posted On:   Friday, April 9, 2004 06:58 AM

In the first case, U r directly having collection of rooms in the house. This is suitable for the specified Problem.

In the second case, U r creating a wrapper over the room collection (called rooms). If U want to do some operations over the collection of rooms etc.. This will be useful. (Accessing rooms with some traversing algorithm).

But accessing rooms in a house not requires any sequence.

This is my suggession about ur problem

Bye

Diwakar R

(diwakar@protechmail.com)

Re: Aggregation or Multiplicity?

Posted By:   Dieter_Decavele
Posted On:   Saturday, April 3, 2004 03:13 AM

You use an association when you only have 1 instance to communicate with.
Aggregation (whole/part relation) is used when you have n instances of some class.
Composition is the same, except that the part (House) can't excist without the whole (Room).

In this case I would take composition as you will always have at least 1 room when you build a house.
The Rooms instance can be removed, the only difference between aggregation and composition representation is that the diamond should be coloured black in a composition.

Example:

House < >----- Room (aggregation)

House <*>----- Room (composition)