Spring] IoC (1)
Spring] IoC (1)
by
by So I got one more run : Philip.Box
category
Inversion of Control
일반적인 (의존성에 대한) 제어권 : "내가 사용할 의존성은 내가 만든다."
class OwnerController{ private OwnerRepository repository = new OwnerRepository(); }
IoC : "내가 사용할 의존성을 누군가 알아서 주겠지."
내가 사용할 의존성의 타입(또는 인터페이스)민 맞으면 어떤거든 상관없다.
그래야 내 코드 테스트 하기도 편하지.
class OwnerController{ private OwnerRepository repo; public OwnerController(OwnerRepository repo){ this.repo = repo; } //repo를 사용합니다. } class OwnerControllerTest{ @Test public void create(){ OwnerRepository repo = new OwnerRepository(); OwnerController controller = new OwnerController(repo); } }
from http://philipbox.tistory.com/86 by ccl(A) rewrite - 2020-03-12 15:54:24
댓글
댓글 쓰기