Skip to content

Commit

Permalink
[Decorator] Added pattern clases
Browse files Browse the repository at this point in the history
  • Loading branch information
luisburgos committed Aug 12, 2015
1 parent cf96a82 commit 413f9d4
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/decorator/pattern/Client.java
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();
}

}
8 changes: 8 additions & 0 deletions src/decorator/pattern/Component.java
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();
}
13 changes: 13 additions & 0 deletions src/decorator/pattern/ConcreteComponent.java
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");
}

}
22 changes: 22 additions & 0 deletions src/decorator/pattern/ConcreteDecoratorOne.java
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.");
}

}
22 changes: 22 additions & 0 deletions src/decorator/pattern/ConcreteDecoratorTwo.java
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.");
}

}
18 changes: 18 additions & 0 deletions src/decorator/pattern/Decorator.java
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();
}
}

0 comments on commit 413f9d4

Please sign in to comment.