Skip to content

Commit

Permalink
고급편/섹션4: 구체 클래스 기반 프록시 - 예제2 (#5)
Browse files Browse the repository at this point in the history
섹션4: 프록시 패턴과 데코레이터 패턴
  • Loading branch information
toychip committed Mar 6, 2024
1 parent f44baaa commit bdda5f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import hello.proxy.pureproxy.concreteproxy.code.ConcreteClient;
import hello.proxy.pureproxy.concreteproxy.code.ConcreteLogic;
import hello.proxy.pureproxy.concreteproxy.code.TimeProxy;
import org.junit.jupiter.api.Test;

public class ConcreteProxyTest {
Expand All @@ -12,4 +13,12 @@ void noProxy() {
ConcreteClient concreteClient = new ConcreteClient(concreteLogic);
concreteClient.execute();
}

@Test
void addProxy() {
ConcreteLogic concreteLogic = new ConcreteLogic();
TimeProxy timeProxy = new TimeProxy(concreteLogic);
ConcreteClient concreteClient = new ConcreteClient(timeProxy);
concreteClient.execute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package hello.proxy.pureproxy.concreteproxy.code;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TimeProxy extends ConcreteLogic {

private ConcreteLogic concreteLogic;

public TimeProxy(final ConcreteLogic concreteLogic) {
this.concreteLogic = concreteLogic;
}

@Override
public String operation() {

log.info("TimeDecorator 실행");
long startTime = System.currentTimeMillis();

String result = concreteLogic.operation();
long endTime = System.currentTimeMillis();

long resultTime = endTime - startTime;
log.info("총 걸린 시간 = {}", resultTime);
return result;
}
}

0 comments on commit bdda5f7

Please sign in to comment.