class Taste
attr soybean_sauce, pepper, glutamate
def initialize(soybean_sauce, pepper, glutamate)
@soybean_sauce = soybean_sauce
@pepper = pepper
@glutamate = glutamate
end
def display
puts "菜的调料含量: 酱油#{@soybean_sauce}, 辣椒#{@pepper},味精#{glutamate}"
end
end
prototype_manager = Hash.new
prototype_manager["温州口味"] = Taste.new("少量", "微乎其微", "越多越好")
prototype_manager["杭州口味"] = Taste.new("少量", "不多", "很少")
order = "温州口味"
food_taste = prototype_manager["温州口味"].clone
food_taste.display
[img]http://dl.iteye.com/upload/attachment/194753/3011ef62-9378-3dcd-8d0f-89239151cf06.gif[/img]
本文通过一个简单的口味配置案例展示了如何使用类来定义不同地区的菜肴口味,包括酱油、辣椒和味精的使用量。并通过原型管理器实现口味的克隆与展示。
1423

被折叠的 条评论
为什么被折叠?



