摘要: 设计模式中常说,组合优于继承,可是组合带来的问题是,你可能要在类中添加wrap方法,委托别的类去做这个实现,举例如下: 1 class Robot 2 def initialize 3 @heat_sensor = HeatSensor.new 4 @arm = RobotArm.new 5 end 6 7 def measure_heat(scale="c") 8 @heat_sensor.measure(scale) 9 end10 11 def stack(boxes_number=1)12 @arm.stack(boxes_num... 阅读全文
posted @ 2011-09-14 00:55 霁雪飘香 阅读(385) 评论(0) 推荐(0) 编辑