A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Engineering
»
OO, Patterns, UML and Refactoring
Author
Decorator Pattern Confusion
Prithvi Sehgal
Ranch Hand
Joined: Oct 13, 2009
Posts: 771
posted
Apr 08, 2012 13:52:43
0
Hi,
I am trying to study Decorator
pattern
from Head First Design
Patterns
but i am unable to understand the basic concept,
can please someone point me towards a compact article or describe decorator pattern with an example.
BR,
Prithvi/Beenish,
My Blog
,
Follow me on Twitter
,
Scjp Tips
,
When you score low in mocks
,
Generics
,
Scjp Notes
,
JavaStudyGroup
Jimmy Clark
Ranch Hand
Joined: Apr 16, 2008
Posts: 2187
posted
Apr 11, 2012 17:47:20
0
public final class InterestCalculatorImpl implements Calculator { public final int calculate() { } } public final class CalculatorDecoratorImpl { private Calculator c; public CalculatorDecoratorImpl(Calculator x) { this.c = x; } /** This method "extends" the functionality of the calcuate method of the InterestCalculatorImpl * without changing any code in the InterestCalculatorImpl class definition */ public final int calculate() { // Lines of code that do something // more lines of code of functionality here int x = c.calculate(); // Lines of code that do something // more lines of code of functionality here // x = x+y; Possible change result of calculate method with different values/equations return x; } }
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: Decorator Pattern Confusion
Similar Threads
Design Pattern
Decorator pattern
Decorator pattern, caching
decorator pattern from HFDP
Visitor - decorator problem
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter