• Like
[JWPA-1]의존성 주입(Dependency injection)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

[JWPA-1]의존성 주입(Dependency injection)

  • 1,262 views
Published

의존성 주입(Dependency Injection)의 개념을 설명하기 위해 만든 강의자료입니다. …

의존성 주입(Dependency Injection)의 개념을 설명하기 위해 만든 강의자료입니다.
의존성 주입이 어떤 방식으로 객체간의 커플링을 느슨하게 만드는지를 설명하고 있습니다.

Published in Software , Education , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,262
On SlideShare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
21
Comments
0
Likes
17

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Java
  • 2.   Web
  • 3.   
  • 4.    Programming
  • 5.   Advanced
  • 6.   
  • 7.    Week01
  • 8.    Dependency Injection 의존성
  • 9.   주입
  • 10.    조영호
  • 11.    snatcher@nhn.com
  • 12.   
  • 13. Dependency
  • 14.   
  • 15. Dependency
  • 16.    변경
  • 17.   
  • 18. Dependency in OO
  • 19.    Method Call
  • 20.    Object A
  • 21.    Object B
  • 22.    Object A
  • 23.    Object B
  • 24.   depends on
  • 25.   
  • 26. in Code
  • 27.    public class MovieLister { public List<Movie> findAll() { ... } } public class MovieFinder { private MovieLister lister; public void moviesDirectedBy(String title) { List<Movie> allMovies = lister.findAll(); ... } } Dependency
  • 28.   
  • 29. class Lecture Class Standard Grader Dependency C o d e Rev i ew 
  • 30.   
  • 31. C o d e Rev i ew 
  • 32.    class Lecture Class Standard Grader Dependency Class PassFail Grader
  • 33. Coupling결합도
  • 34.    = Coupling
  • 35.    Object A
  • 36.    Object B
  • 37.    Dependency
  • 38.   
  • 39. = Coupling
  • 40.    Object A
  • 41.    Object B
  • 42.    Dependency
  • 43.    Coupling은
  • 44.   반드시
  • 45.   필요
  • 46.    OO의
  • 47.   기반은
  • 48.   
  • 49.   객체와
  • 50.   객체
  • 51.   간의
  • 52.   메시지
  • 53.   전송
  • 54.   
  • 55. Goal
  • 56.    의존성을
  • 57.   없애는
  • 58.   것이
  • 59.   아니라
  • 60.    결합도를
  • 61.   낮추는
  • 62.   것
  • 63.    = Coupling
  • 64.    Object A
  • 65.    Object B
  • 66.    Dependency
  • 67.   
  • 68. Tight Coupling?
  • 69.    대상에
  • 70.   대해
  • 71.   
  • 72.    더
  • 73.   많이
  • 74.   가정해야하는
  • 75.   것
  • 76.   
  • 77. class Lecture Class Standard Grader Dependency P ro bl e m 
  • 78.    Class Dependency
  • 79. P ro bl e m 
  • 80.    class Lecture Class Standard Grader Dependency Class PassFail Grader Class 대상
  • 81.   수정
  • 82. P ro bl e m 
  • 83.    class Lecture Class Standard Grader Dependency Class PassFail Grader Tight Coupling Dependency
  • 84. S o l u t i o n 
  • 85.    class Lecture Class Standard Grader Class PassFail Grader Dependency Abstraction Loose Coupling
  • 86. S o l u t i o n 
  • 87.    class Lecture Class Standard Grader Class PassFail Grader Dependency Abstract Class interface Loose Coupling
  • 88. S o l u t i o n 
  • 89.    class Lecture Dependency Abstract Class interface Loose Coupling 클래스에
  • 90.   대한
  • 91.   가정
  • 92.   제거
  • 93.    단지
  • 94.   행위에
  • 95.   대해서만
  • 96.   가정
  • 97.   
  • 98. Interface? Discussion
  • 99. Behavior Discussion
  • 100. class Lecture grade() Lecture의
  • 101.   입장에서
  • 102.   
  • 103.    Grade를
  • 104.   산출하는
  • 105.   동일한
  • 106.   행위를
  • 107.   제공하는
  • 108.   
  • 109.    모든
  • 110.   객체와
  • 111.   협력
  • 112.   가능
  • 113.    Discussion class class class
  • 114. class Lecture grade() Lecture의
  • 115.   입장에서
  • 116.   
  • 117.    Grade를
  • 118.   산출하는
  • 119.   동일한
  • 120.   인터페이스를
  • 121.   제공하는
  • 122.   
  • 123.    모든
  • 124.   객체와
  • 125.   협력
  • 126.   가능
  • 127.    Discussion class class class
  • 128. class Lecture grade() Lecture는
  • 129.   
  • 130.    다양한
  • 131.   객체들과
  • 132.   협력
  • 133.   가능
  • 134.    Discussion class class class
  • 135. class Lecture grade() Lecture는
  • 136.   
  • 137.    다양한
  • 138.   객체들과
  • 139.   협력
  • 140.   가능하기
  • 141.   때문에
  • 142.   
  • 143.    설계가
  • 144.   유연함
  • 145.    Discussion class class class
  • 146. class Lecture grade() Lecture는
  • 147.   
  • 148.    다양한
  • 149.   상황에서
  • 150.    재사용이
  • 151.   가능
  • 152.    Discussion class class class
  • 153. class Lecture grade() 단,
  • 154.   Lecture가
  • 155.   
  • 156.    구체적인
  • 157.   클래스와
  • 158.   결합되면
  • 159.   
  • 160.    위에서
  • 161.   나열한
  • 162.   장점을
  • 163.   누릴
  • 164.   수
  • 165.   없음
  • 166.    Discussion class class class
  • 167. class Lecture grade() Lecture는
  • 168.   
  • 169.    구체적인
  • 170.   클래스가
  • 171.   아니라
  • 172.    행위에만
  • 173.   의존해야
  • 174.   함
  • 175.    Discussion class class class
  • 176. Program to an interface, not implementation
  • 177. class Lecture grade() Java interface Discussion class class class interface
  • 178. Refactoring
  • 179. P ro bl e m 
  • 180.    class Lecture Class StandardGrader Class PassFailGrader interface Grader Create Dependency Dependency Use Tight Coupling Class Dependency
  • 181. S o l u t i o n 
  • 182.    class Lecture Class StandardGrader Class PassFailGrader interface Grader Create Dependency Dependency Use Separate Use From Construction
  • 183. S o l u t i o n 
  • 184.    class Lecture Class StandardGrader Class PassFailGrader interface Grader Create Dependency Dependency Use Client Dependency Use Separate Use From Construction
  • 185. S o l u t i o n 
  • 186.    class Lecture Class StandardGrader Class PassFailGrader interface Grader Dependency Use Client Dependency Use Separate Use From Construction Create Dependency
  • 187. S o l u t i o n 
  • 188.    class Lecture Class StandardGrader Class PassFailGrader interface Grader Dependency Use Client Dependency Use Separate Use From Construction Create Dependency inject Dependency
  • 189. Refactoring
  • 190. Lecture lecture = new Lecture(new StandardGrader(), 80, 90, 65); String grade = lecture.grade(); Lecture lecture = new Lecture(new PassFailGrader(), 80, 90, 65); String grade = lecture.grade(); Lecture의 Client가 Lecture가 사용할(Use) Grader를 생성(Create)한 후 Lecture에게 주입 (Dependency Injection)
  • 191. Program to an interface, not implementation Dependency Injection
  • 192. Lecture lecture = new Lecture(new StandardGrader(), 80, 90, 65); String grade = lecture.grade(); Lecture lecture = new Lecture(new PassFailGrader(), 80, 90, 65); String grade = lecture.grade(); Lecture를
  • 193.   사용하는
  • 194.   모든
  • 195.   곳에서
  • 196.   
  • 197.    이런
  • 198.   일을
  • 199.   하기
  • 200.   귀찮겠죠?
  • 201.   
  • 202. S o l u t i o n 
  • 203.    class Lecture Class StandardGrader Class PassFailGrader interface Grader Dependency Use Client Dependency Use Dependency Injection Framework inject Dependency
  • 204. Spring
  • 205.    @Controller public class ManageBookController { @Autowired private BookstoreService bookstoreService; @Autowired private CategoryService categoryService;
  • 206. Dependency Injection & Interface Discussion Flexibility Testability Reusability
  • 207. Interface & Dynamic Type Language Discussion
  • 208. class Lecture: def __init__(self, grader, scores): self.scores = scores self.grader = grader def grade(self): return self.grader.grade(self.scores) class StandardGrader: def grade(self): ... class PassFailGrader: def grade(self): ... ex) Python