title: Should I use inheritance or composition?
body: <p>I would like to keep this one short. I build a HouseA that has two rooms, say <code>BedRoom</code> and <code>StudyRoom</code>, both deriving from a base class called <code>Room</code>.
  <code>BedRoom</code> and <code>StudyRoom</code> have a same parent called <code>House</code>. Also, any room in a house can access any other rooms only through the parent. If <code>BedRoom</code> has to access any attribute of <code>StudyRoom</code>, it has to go only via <code>House</code> (i.e. parent) and vice-versa.</p>
  
  <pre><code>HouseA ISA House
  HouseA HAS BedRoom and StudyRoom.
  BedRoom ISA Room
  StudyRoom ISA Room
  </code></pre>
  
  <p>Now the Problem: Let's say, I build another home (say <code>HouseB</code>), which is a exactly the same as the above, but with one change. I don't want two separate rooms (i.e. <code>BedRoom</code> and <code>StudyRoom</code>), but instead a single room (<code>MasterRoom</code>) which has both these facilities. 
  For the sake of code reusability, I could think of the following design options:</p>
  
  <pre><code>Option-1:
  HouseB ISA House
  HouseB HAS MasterRoom
  MasterRoom ISA Room
  </code></pre>
  
  <p>Here I lose the ability to reuse the attributes of <code>BedRoom</code> and <code>StudyRoom</code> that I created for <code>HouseA</code>. Note that most of the attributes of <code>BedRoom</code> and <code>StudyRoom</code> need to be reimplemented in <code>MasterRoom</code> anyway, thereby resulting in code duplication.</p>
  
  <pre><code>Option-2:
  HouseB ISA House
  HouseB HAS MasterRoom
  MasterRoom ISA Room
  MasterRoom HAS LogicalBedroom
  MasterRoom HAS LogicalStudyRoom
  LogicalBedroom ISA BedRoom
  LogicalStudyRoom ISA StudyRoom
  </code></pre>
  
  <p>This way, I use composition so that I could reuse most of my code (I have several thousand lines of code that I could reuse), but the problem is that <code>BedRoom</code> is a concrete class and <code>logicalBedRoom</code> may find certain attributes not suitable and may be forced to override  methods so that they do nothing.  For example, <code>Bedroom-&gt;noOfSides() = 4</code> and <code>logicalBedRoom-&gt;noOfSides() = ??</code>. Is this a good use of inheritance?</p>
  
  <p>My actual design is for a complex chip that combines the functionality of two individual chips (I used House (motherboard) and Room (chip) analogy). I code in Object Oriented Perl and I would really appreciate any alternate design suggestions.</p>
  
  <p>Thanks</p>