서비스 중인 어플리케이션에서 병목현상이 발생하여 각 메서드를 추적하기 위한 로그 추적기를 추가하기로 하였다. 로그 추적기는 메서드가 시작하는 시간과 끝나는 시간을 측정하여 각 메서드를 처리하는데 걸리는 시간이 얼마나 되는지 확인하는 기능을 한다.아래 코드는 로그 추적기
지난 포스팅에서 템플릿 메서드 패턴을 활용해 SRP를 준수함으로 코드의 변경에 유연한 로직을 작성해보았다. 하지만 템플릿 메서드 패턴은 단점이 있다. 상속을 이용하여 구현하기 때문에 컴파일 시점에 자식 클래스가 부모 클래스를 강하게 의존한다는 것이다. 자식 클래스에서는
앞선 포스팅에서 전략 패턴에 대해서 알아보았다. 아래의 코드는 전략 패턴에서 봤던 Context이다. 여기서 ContextV2는 변하지 않는 템플릿 역할을 하고, 변하는 부분은 Strategy의 코드를 실행해서 처리한다. 이처럼 다른 코드의 인수로서 넘겨주는 실행 가