This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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: 1400
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!