public class ProxyPatternTest {
@Test
void noProxy() { //매번 3번의 실행 로직 사용
RealSubject realSubject = new RealSubject();
ProxyPatternClient client = new ProxyPatternClient(realSubject);
client.execute();
client.execute();
client.execute();
}
@Test
void cacheProxy() { //1번의 실행 로직 후 저장된 값 실행
RealSubject realSubject = new RealSubject();
CacheProxy cacheProxy = new CacheProxy(realSubject);
ProxyPatternClient client = new ProxyPatternClient(cacheProxy);
client.execute();
client.execute();
client.execute();
}
}
@Slf4j
public class DecoratorPatternTest {
@Test
void noDecorator() { //realComponent의 기능 사용
Component realComponent = new RealComponent();
DecoratorPatternClient client = new DecoratorPatternClient(realComponent);
client.execute();
}
@Test
void decorator() { //realComponent의 기능에서 데코레이터들로 추가 기능 부여
Component realComponent = new RealComponent();
Component messageDecorator = new MessageDecorator(realComponent);
Component timeDecorator = new TimeDecorator(messageDecorator);
DecoratorPatternClient client = new DecoratorPatternClient(timeDecorator);
client.execute();
}
}