객체 지향 프로그래밍 설계의 다섯가지 기본 원칙(SOLID)

hankyulee·2022년 9월 25일
0

인터뷰

목록 보기
8/12

SRP: If there is a change in business logic, we need to touch view controller, if there is a change in validation logic, again we need to touch view controller which can make it fragile and it will be difficult to write tests for this kind of code. Changes in web request can be requested from the back-end team while changes in business logic can be requested from the business side. In any case, changes requested from one person shouldn’t modify code responsible for other people. 테스트도 용이해지게 된다. 왜냐하면 여러 클래스에 같은 기능을 하는 메소드만 모여있기 때문. 여러클래스를 따로 테스트하면 좋기때문.

ref: https://medium.com/swift-india/solid-principles-part-1-single-responsibility-ccfd4ff34a5a

o: 확장에 열려있다는 것은, 수고롭지 않게 클래스의 기능을 확장할 수 있다는 것이다. 
또한 변경에 닫혀있다는 것은, 기존에 구현되어 있는 것들을 바꾸지 않고 클래스를 확장할 수 있어야 한다는 것이다. 추상화를 통해 가능하다.
출처: https://leechamin.tistory.com/518 [참신러닝 (Fresh-Learning):티스토리]

의존 역전 원칙은 의존 관계가 생길때 변하기 쉬운거 보다 변하기 어려운 것에 의존해야 한다는 원칙입니다.즉 DIP를 위배하지 않으려면 의존 시 클래스보다는 인터페이스 혹은 추상 클래스와 관계를 맺는게 맞습니다.By injecting the request manager, the view controller doesn't know how to instantiate the request manager. Unit testing is so much easier with dependency injection. Dependency injection makes it very easy to replace an object's dependencies with mock objects
의존성 분리의 조건을 만족시켜야 DI 라고 한다.
그리고 의존성 분리는 "의존 역전의 원칙"을 기반으로 분리를 실행한다.

  • 의존관계를 맺을때 프로토콜 사용이유

클래스에서 프로토콜에게 의존의 방향이 역전 되었다고 한다.

https://cocoacasts.com/dependency-injection-in-swift
관심사의 분리: https://www.swiftbysundell.com/articles/separation-of-concerns-using-protocols-in-swift/#another-abstraction
ref: https://green1229.tistory.com/163

LSP: 상속받은애를 수정하지 않고도 정상동작 가능한가
https://inuplace.tistory.com/943

0개의 댓글