JDK中对装饰器模式的使用
类图
java.io.FilterInputStream
- InputStream 作为抽象构件,连接具体构件和装饰器;
- FilterInputStream 作为抽象装饰器,继承并组合了 InputStream;
- ByteInputStream 作为 InputStream 的实现类,充当具体构件的角色;
- 其3个子类作为具体装饰器,可以装饰 ByteInputStream ,并再次作为具体构件被装饰;
public
class FilterInputStream extends InputStream {
/**
* The input stream to be filtered.
*/
protected volatile InputStream in;
// ...
}
Spring中对装饰器模式的使用
public class TransactionAwareCacheDecorator implements Cache {
private final Cache targetCache;
// ...
}