what kind of relationship is there between a common wall and the rooms that located next to it?
Posted
by
siamak
on Stack Overflow
See other posts from Stack Overflow
or by siamak
Published on 2012-06-27T23:33:29Z
Indexed on
2012/07/05
21:16 UTC
Read the original article
Hit count: 322
I want to know whats the Relationship between a common wall (that are located In an adjoining room ) and the rooms.
As i know the relationship between a room and its walls is Composition not Aggregation
(am i right ?)
And according to the definition of
Composition the contained object can't be shared between two
containers, whereas in
aggregation it is possible
.
now i am confused that whats the best modeling approach to represent the relationship between a common wall and the rooms located next to it ?
It would be highly Appreciated if you could provide your advices with some code.
|--------|--------|
Approch1:
(wall class ---- room class) /Composition
Approach2:
wall class ----- room class /Aggregation
Approch3:
we have a wall class and a Common wall class , Common wall class inherits from wall class
adjoining room class ---- (1) Common wall class /Aggregation
adjoining room class ---- (6) wall class / composition
Approach4: I am a developer not a designer :) so this is my idea :
class Room
{
private wall _firstwall ;
private wall _secondtwall;
private wall _thirdwall ;
private wall _commonwall ;
public Room( CommonWall commonwall)
{
_firstwall=new Wall();
_secondtwall=new Wall();
_thirdwall=new Wall();
_commonwall=commonwall;
}
}
Class CommonWall:Wall
{
//...
}
// in somewher :
static void main()
{
Wall _commonWall=new Wall();
Room room1=new Room(_commonWall);
Room room2=new Room(_commonWall);
Room [] adjacentRoom =new Room[2]{room1,room2};
}
Edit 1: I think this is a clear question but just for more clarification :
The point of the question is to find out whats the best pattern or approach to model a relationship for an object that is a component of two other objects in the same time.
and about my example : waht i mean by a "room" ?,surely i mean an enclosed square room with 4 walls and one door.but in this case one of these walls is a common wall and is shared between two adjacent rooms.
© Stack Overflow or respective owner