티스토리 뷰
작성중...
.
.
.
.
.
.
.
.
.
class DocumentOpener {
let urlOpener: URLOpening
init(application: URLOpening = UIApplication.shared) {
self.urlOpener = urlOpener
}
func open(_ document: Document, mode: OpenMode) {
let modeString = mode.rawValue
let url = URL(string: "myappscheme://open?id=\(document.identifier)&mode=\(modeString)")!
if urlOpener.canOpenURL(url) {
urlOpener.open(url, options: [:], completionHandler: nil)
} else {
handleURLError()
}
}
}
장점
- The test does not need an instance of UIViewController to test the
DocumentOpener
- The test is non-deterministic
- The class allows for dependency injection through parameterization
- The URLOpening protocol decouples the DocumentOpener code from a specific implementation
- DocumentOpener is simple and elegant to use because you don’t need to pass in a dependency
- If you want to use a different default you only need to change it in one place
단점
- The DocumentOpener is still coupled to UIApplication
- It presents a practice that is ill-advised in a different circumstance
왜 안티패턴??
애플은 왜 이렇게 씀??
참고
Why did Apple Advocate for Bastard Injection?
Implementing Dependency Injection in Swift [Tutorial]
Singleton Pattern * Dependency Injection * Service Locator
'iOS' 카테고리의 다른 글
[번역] WatchKit (0) | 2022.01.20 |
---|---|
iOS status bar style 변경하기 (1) | 2021.11.18 |
iOS TextField memory leak (0) | 2021.07.16 |
iOS App Life Cycle (2) | 2021.07.11 |
swift static, class, final class (0) | 2020.08.02 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 스토아학파
- 프론트엔드 공부
- statusBarStyle
- 철학의 역사
- bitbucket
- watchKit
- Localizable
- StatusBar
- 생활코딩
- private repository
- watchOS life cycle
- Xcode
- Android
- 읏샷샤 화이팅 앗샷샤 화이팅
- spm
- 에피큐어
- watchOS
- 냉철
- 에피쿠로스
- iOS App Life Cycle
- iPadOS
- lldb
- iPad
- strings.xml
- ios
- split view controller
- opentutorial
- UISplitViewController
- SplitViewController
- 클론코딩
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함