开发者

in the Decorator pattern why does the abstract decorator need the abstract component

http://en.wikipedia.org/wiki/File:Decor开发者_开发百科ator_UML_class_diagram.svg

I'm a little confused about why the abstract Decorator class would need to store (wrap) the abstract component class, what the use case for this?


The basic function of the decorator is to wrap and potentially alter the method calls of the wrapped component while implementing the same interface.

You doesn't strictly have to define an abstract Decorator class, but if you do, it makes sense for it to contain the base component class, as all the concrete implementations will.

A decorator usually functions by defining methods that call the corresponding methods of the wrapped component, but doing something else before, after or both.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜