Skip to content

Commit 7f593cd

Browse files
committed
고급편/섹션4: 데코레이터 패턴 - 예제 코드1 (#5)
섹션4: 프록시 패턴과 데코레이터 패턴
1 parent 79d507a commit 7f593cd

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package hello.proxy.pureproxy.decorator;
2+
3+
import hello.proxy.pureproxy.decorator.code.DecoratorPatternClient;
4+
import hello.proxy.pureproxy.decorator.code.RealComponent;
5+
import lombok.extern.slf4j.Slf4j;
6+
import org.junit.jupiter.api.Test;
7+
8+
@Slf4j
9+
public class DecoratorPatternTest {
10+
11+
@Test
12+
void noDecoration() {
13+
RealComponent realComponent = new RealComponent();
14+
DecoratorPatternClient client = new DecoratorPatternClient(realComponent);
15+
16+
client.execute();
17+
client.execute();
18+
client.execute();
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package hello.proxy.pureproxy.decorator.code;
2+
3+
public interface Component {
4+
String operation();
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package hello.proxy.pureproxy.decorator.code;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
5+
@Slf4j
6+
public class DecoratorPatternClient {
7+
8+
private Component component;
9+
10+
public DecoratorPatternClient(final Component component) {
11+
this.component = component;
12+
}
13+
14+
public void execute() {
15+
String operation = component.operation();
16+
log.info("result = {}", operation);
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package hello.proxy.pureproxy.decorator.code;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
5+
@Slf4j
6+
public class RealComponent implements Component {
7+
@Override
8+
public String operation() {
9+
log.info("RealComponent 실행");
10+
return "data";
11+
}
12+
}

0 commit comments

Comments
 (0)