forked from luisburgos/design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf96a82
commit 413f9d4
Showing
6 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package decorator.pattern; | ||
|
||
/** | ||
* Created by luisburgos on 11/08/15. | ||
*/ | ||
public class Client { | ||
|
||
public static void main(String[] args) { | ||
|
||
Component component = new ConcreteDecoratorOne(new ConcreteComponent()); | ||
component.doOperation(); | ||
System.out.println("Adding concrete component two..."); | ||
component = new ConcreteDecoratorOne(new ConcreteDecoratorTwo(new ConcreteComponent())); | ||
component.doOperation(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package decorator.pattern; | ||
|
||
/** | ||
* Created by luisburgos on 11/08/15. | ||
*/ | ||
public interface Component { | ||
public void doOperation(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package decorator.pattern; | ||
|
||
/** | ||
* Created by luisburgos on 11/08/15. | ||
*/ | ||
public class ConcreteComponent implements Component { | ||
|
||
@Override | ||
public void doOperation() { | ||
System.out.println("Concrete Component doing operation"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package decorator.pattern; | ||
|
||
/** | ||
* Created by luisburgos on 11/08/15. | ||
*/ | ||
public class ConcreteDecoratorOne extends Decorator { | ||
|
||
public ConcreteDecoratorOne(Component component) { | ||
super(component); | ||
} | ||
|
||
@Override | ||
public void doOperation() { | ||
super.doOperation(); | ||
doAdditionalOperation(); | ||
} | ||
|
||
public void doAdditionalOperation() { | ||
System.out.println("Doing additional operation concrete decorator ONE."); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package decorator.pattern; | ||
|
||
/** | ||
* Created by luisburgos on 11/08/15. | ||
*/ | ||
public class ConcreteDecoratorTwo extends Decorator{ | ||
|
||
public ConcreteDecoratorTwo(Component component) { | ||
super(component); | ||
} | ||
|
||
@Override | ||
public void doOperation() { | ||
super.doOperation(); | ||
doAdditionalOperation(); | ||
} | ||
|
||
public void doAdditionalOperation() { | ||
System.out.println("Doing additional operation concrete decorator TWO."); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package decorator.pattern; | ||
|
||
/** | ||
* Created by luisburgos on 11/08/15. | ||
*/ | ||
public abstract class Decorator implements Component { | ||
|
||
protected Component component; | ||
|
||
public Decorator(Component component){ | ||
this.component = component; | ||
} | ||
|
||
@Override | ||
public void doOperation() { | ||
component.doOperation(); | ||
} | ||
} |