Note that there are some explanatory texts on larger screens.

plurals
  1. POwhat kind of relationship is there between a common wall and the rooms that located next to it?
    text
    copied!<p>I want to know whats the Relationship between a common wall (that are located In an adjoining room ) and the rooms.<br> As i know the relationship between a room and its walls is <code>Composition not Aggregation</code> (am i right ?) </p> <p><code>And according to the definition of</code> <strong>Composition</strong> <code>the contained object can't be shared between two</code> <code>containers, whereas in</code> <strong>aggregation</strong> <code>it is possible</code>. </p> <p>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 ?</p> <p><em>It would be highly Appreciated if you could provide your advices with some code.</em></p> <p>|--------|--------|</p> <p><strong>Approch1:</strong></p> <pre><code>(wall class ---- room class) /Composition </code></pre> <p><strong>Approach2:</strong></p> <pre><code>wall class ----- room class /Aggregation </code></pre> <p><strong>Approch3:</strong></p> <p>we have a wall class and a Common wall class , Common wall class inherits from wall class</p> <pre><code>adjoining room class ---- (1) Common wall class /Aggregation adjoining room class ---- (6) wall class / composition </code></pre> <p><strong>Approach4:</strong> I am a developer not a designer :) so this is my idea :</p> <pre><code>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 { //... } </code></pre> <p>// in somewher :</p> <pre><code> static void main() { Wall _commonWall=new Wall(); Room room1=new Room(_commonWall); Room room2=new Room(_commonWall); Room [] adjacentRoom =new Room[2]{room1,room2}; } </code></pre> <p><strong>Edit 1:</strong> <em>I think this is a clear question but just for more clarification :</em></p> <p><strong>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</strong>.</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload