decorator 模式

王朝other·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

decorator for non-visualable class e.g. java.io.*

The class FilterInputStream itself simply overrides all methods of InputStream with versions that pass all requests to the underlying input stream. Subclasses of FilterInputStream may further override some of these methods as well as provide additional methods and fields.

The FilterInputStream class is thus a Decorator that can be wrapped around any input stream class. It is essentially an abstract class that doesn’t do any processing, but provides a layer where the relevant methods have been duplicated. It normally forwards these method calls to the enclosed parent stream class. The interesting classes derived from FilterInputStream include:

BufferedInputStream Adds buffering to stream so that every call does

not cause I/O to occur.

CheckedInputStream Maintains a checksum of bytes as they are read

DataInputStream Reads primitive types (Long, Boolean, Float, etc.)

from the input stream.

DigestInputStream Computes a MessageDigest of any input stream.

InflaterInputStream Implements methods for uncompressing data.

PushbackInputStream Provides a buffer where data can be “unread,” if

during parsing you discover you need to back up.

看了看Decorator设计模式,本想留个笔记,看了此文,觉得经典,原样转来

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航