Java Reference
In-Depth Information
SSTTRRAANNGGEE ffiittss ooff ppaassssiioonn hhaavvee II kknnoowwnn::
AAnndd II wwiillll ddaarree ttoo tteellll,,
BBuutt iinn tthhee lloovveerr''ss eeaarr aalloonnee,,
WWhhaatt oonnccee ttoo mmee bbeeffeellll..
Output Stream Meets the Decorator Pattern
Figure 7-6 depicts the class diagram that includes some commonly used output stream classes. You can refer to the
API documentation of the java.io package for the complete list of the output stream classes. The comments in the
class diagram compare the output stream classes with the classes required to implement the decorator pattern. Notice
that the class diagram for the output stream is similar to that of the input stream and the drink application.
Figure 7-6. Some commonly used classes for output streams compared with the decorator pattern
Most of the times, if you know the name of the input stream class, you can get the corresponding output stream
class by replacing the word “Input” in the class name with the word “Output.” For example, for the FileInputStream
class, you have a corresponding FileOutputStream class; for the BufferedInputStream class, you have a
corresponding BufferedOutputStream class, and so on. You may not find a corresponding output stream class for
every input stream class; for example, PushbackInputStream class has no corresponding output stream class. You may
find some new classes that are not in the input stream class hierarchy because they do not make sense while reading
data; for example, you have a new concrete decorator class PrintStream in the output stream class hierarchy. Table 7-3
compares the classes in the decorator pattern, your drink application, and the output streams.
 
Search WWH ::




Custom Search