Re: [模式] 装饰者模式(decorator)只有一种结构吗?

楼主: qrtt1 (有些事,有时候。。。)   2013-01-12 20:17:00
※ 引述《worldxxi ()》之铭言:
: 今天上课讲到decorator pattern,我有个疑问就是,为什么设计上不写成这样
: abstract class 主餐
: {
: protect 副食品 list;
: abstract public int cost();
: }
: class 猪排 : 主餐
: {
: public override int cost()
: {
: return 130 + all list cost;
: }
: }
: ...
: abstract class 副食品
: {
: }
: class 味增汤 : 副食品
: {
: public override int cost()
: {
: return 50;
: }
: }
: ...
: 那个all list cost在哪边做先不管,我的意思是UML继承架构不要让副食品继承主餐,
: 而是让而是用 1

Links booklink

Contact Us: admin [ a t ] ucptt.com