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 Decorator pattern 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 "Decorator pattern" Watch "Decorator pattern" New topic

Decorator pattern

Priya Bindra
Ranch Hand

Joined: Sep 22, 2009
Posts: 51
I dont understand how decorator pattern is different from sublassing.

Wiki says that: "The decorator pattern is an alternative to subclassing. Subclassing adds behaviour at compile time, and the change affects all instances of the original class; decorating can provide new behaviour at runtime for individual objects."

Can someone explain.
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
This link should help you


Failure is not an option.
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1404
EJB deployment descriptor adds beans behavior at run-time using decorator design pattern. Inheritance adds behavior during compile time.
I agree. Here's the link:
subject: Decorator pattern
It's not a secret anymore!