Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Give me example of Decorater

 
Umair Uddin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please some body give me the example of Decorater.
Umair Uddin
------------------
 
narasimha reddy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)
The best example can be I/O streams in java.
Normally whenever u create input or output stream, you will create bufferstream by passing the create I/O stream as parameter so that additional functionality to the stream can be provided by bufferstream.
ex.. new BufferInputStream(new InputStream(new File())).....
2) In AWT, all the decorations to the components(say borders etc) are provided through Decorator Pattern.
I hope now you got better idea about how decorator pattern works.
 
Alan Shalloway
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a good example. You can see more on this in Bruce Eckel's free electronic book- Thinking in Java, 2nd Ed. Go to http://www.mindview.net/Books/TIJ/ He describes how Java's I/O is controlled with the decorator.

------------------
Alan Shalloway.
Look for Jim Trott and my book: Design Patterns Explained
Visit our site Net Objectives.
Visit our Design Patterns Explained Community of Practice
Check out our CDROM based audio training in XML
 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's also some interesting stuff on the Wiki patterns site:
http://wiki.cs.uiuc.edu/PatternStories/DecoratorPattern
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic