Should I use inheritance or composition?

后端 未结 1 691
臣服心动
臣服心动 2020-12-08 22:32

I would like to keep this one short. I build a HouseA that has two rooms, say BedRoom and StudyRoom, both deriving from a base class called R

1条回答
  •  感情败类
    2020-12-08 23:01

    Why not use roles to achieve this:

    House A has a Bedroom
    Bedroom does SleepingArea
    House has a Studyroom
    Studyroom does ComfyArea
    
    House B has a MasterRoom
    MasterRoom does SleepingArea and ComfyArea
    

    The easiest way to get roles is to use Moose.

    0 讨论(0)
提交回复
热议问题