Inheritance vs. Composition : Composition « Class « Flash / Flex / ActionScript






Inheritance vs. Composition

 
package
{
    public class House
    {
        public var kitchen:Kitchen;
        public var livingroom:LivingRoom;
        public var bedrooms:Array;

        public function House(numberOfBeds:int)
        {
            kitchen = new Kitchen();
            livingroom = new LivingRoom();
            bedrooms = new Array();
            for (var i:int = 0; i < numberOfBeds; i++)
            {
                bedrooms[i] = new Bedroom();
            }
        }
    }

}
class Kitchen{
}
class LivingRoom{
}
class Bedroom{
}

        








Related examples in the same category

1.Class composition