Skip to content

Commit

Permalink
add: 제어의 역전
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeyeon.seo committed Nov 6, 2020
1 parent ec07662 commit d248362
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
@@ -0,0 +1,14 @@
package com.javabom.toby.chapter1.term.제어의_역전;

public class IoCContainer {

/**
* IoC: 제어의 역전
* UserService의 UserRepository 구현체에 대한 생성의 책임을 IoCContainer에 위임한다.
*
* @return
*/
public UserService javabomUserService() {
return new UserService(new JavabomUserRepository());
}
}
@@ -0,0 +1,4 @@
package com.javabom.toby.chapter1.term.제어의_역전;

public class JavabomUserRepository implements UserRepository {
}
@@ -0,0 +1,4 @@
package com.javabom.toby.chapter1.term.제어의_역전;

public interface UserRepository {
}
@@ -0,0 +1,9 @@
package com.javabom.toby.chapter1.term.제어의_역전;

public class UserService {
private final UserRepository userRepository;

public UserService(UserRepository userRepository) {
this.userRepository = userRepository;
}
}
@@ -0,0 +1,16 @@
package com.javabom.toby.chapter1.term.제어의_역전;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

class IoCContainerTest {

@DisplayName("클라이언트는 IoCContainer를 통해 UserService를 얻는다")
@Test
void ioc() {
IoCContainer container = new IoCContainer();
UserService userService = container.javabomUserService();
}


}

0 comments on commit d248362

Please sign in to comment.