Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Decorator Pattern and Java API

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was studying the use of Decorator in the java.io package. According to the GoF book it's a good idea to have a "base" decorator which handles the job of delegating requests to the contained object for all methods.
I noticed that for InputStreams, the class FilterInputStream serves as a "base" decorator class, while in Readers there is no "base" decorator class. Actually FilterReader seems to be intended for that role, but then BufferedReader (which is a decorator) does not extend from it.
What is the reason for this incosistency? According to the book if there is only one decorator then there is no need for a "base" but that doesn't seem to fit the case here.
Thanks.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does any body have answer to this?
 
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I have.

Read the javadoc line from FilterInputStream;

The class <code>FilterInputStream</code>
* itself simply overrides all methods of
* <code>InputStream</code> with versions that
* pass all requests to the contained input
* stream



While FilterInputStream overrides all methods of InputStream, the same is not true for FilterReader and Reader.

Hope that makes sense to you about the decision of FilterReader being not the base class for other Reader's
 
Saloon Keeper
Posts: 27930
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I'd consider the IO stream processors to be decorators, to tell the truth.

However, design patterns are advisory, not concrete, and I'm not even sure if the GoF had actually written their book back when this stuff was originally designed. Much less any decision on Sun's part to go all "pattern-y".
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic