Skip to content

Commit

Permalink
고급편/섹션4: 데코레이터 패턴 - 예제 코드1 (#5)
Browse files Browse the repository at this point in the history
섹션4: 프록시 패턴과 데코레이터 패턴
  • Loading branch information
toychip committed Mar 6, 2024
1 parent 79d507a commit 7f593cd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package hello.proxy.pureproxy.decorator;

import hello.proxy.pureproxy.decorator.code.DecoratorPatternClient;
import hello.proxy.pureproxy.decorator.code.RealComponent;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

@Slf4j
public class DecoratorPatternTest {

@Test
void noDecoration() {
RealComponent realComponent = new RealComponent();
DecoratorPatternClient client = new DecoratorPatternClient(realComponent);

client.execute();
client.execute();
client.execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package hello.proxy.pureproxy.decorator.code;

public interface Component {
String operation();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package hello.proxy.pureproxy.decorator.code;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DecoratorPatternClient {

private Component component;

public DecoratorPatternClient(final Component component) {
this.component = component;
}

public void execute() {
String operation = component.operation();
log.info("result = {}", operation);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package hello.proxy.pureproxy.decorator.code;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RealComponent implements Component {
@Override
public String operation() {
log.info("RealComponent 실행");
return "data";
}
}

0 comments on commit 7f593cd

Please sign in to comment.