Should I use inheritance or composition?

后端 未结 1 686
臣服心动
臣服心动 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)
提交回复
热议问题