File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes OO, Patterns, UML and Refactoring and the fly likes Give me example of Decorater Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Give me example of Decorater" Watch "Give me example of Decorater" New topic

Give me example of Decorater

Umair Uddin

Joined: Sep 12, 2001
Posts: 14
please some body give me the example of Decorater.
Umair Uddin
narasimha reddy

Joined: Nov 24, 2001
Posts: 13
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.

Narasimha Reddy<BR>---------------<BR>Sun certified Enterprise architect(Part-I)<BR>Sun Certified Web Component Developer<BR>IBM Certified in OOAD with UML<BR>IBM Certified in enterprise connectivity test<BR>Oracle Certified in SQL and PL/SQL.<BR>Sun Certified Java2 Programmer
Alan Shalloway
Ranch Hand

Joined: Sep 26, 2001
Posts: 60
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 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

Alan Shalloway.<BR>Look for Jim Trott and my book: <A HREF="" TARGET=_blank rel="nofollow">Design Patterns Explained</A><BR>Visit our site <A HREF="" TARGET=_blank rel="nofollow">Net Objectives</A>.<BR>Visit our <A HREF="" TARGET=_blank rel="nofollow">Design Patterns Explained Community of Practice</A><BR>Check out our <A HREF="" TARGET=_blank rel="nofollow">CDROM based audio training in XML</A>
Jim Baiter
Ranch Hand

Joined: Jan 05, 2001
Posts: 532
There's also some interesting stuff on the Wiki patterns site:
Don't get me started about those stupid light bulbs.
subject: Give me example of Decorater
It's not a secret anymore!