Protocol Oriented Programming Overview
Protocol in Objective-C
- 단지 기능의 청사진의 역할을 수행
- 주로 Delegate, DataSource 등으로 이용
- 기본 구현(Default Implementation) 불가
Protocol in Swift
- Objective-C의 프로토콜 기능은 기본
- 기본 구현(Default Implementation) 가능
- Protocol + Extension = Protocol extension
- 특정 타입이 할 일 지정 + 구현을 한 방에 함!
Protocol extension
protocol LayoutDrawable {
func drawSomeLayout()
}
class MyView: UIView, LayoutDrawable {
}
extension LayoutDrawable {
func drawSomeLayout() {
// Draw some layout..
}
}
Idea from?
-
상속의 한계
- 서로 다른 클래스에서 상속받은 클래스는 동일한 기능을 구현하기 위해 중복코드 발생
-
카테코리의 한계 및 부작용
- 프로퍼티 추가 불가
- 오직 클래스에만 적용 가능
- 기존 메서드를 (자신도 모르게) Override 가능
-
참조타입의 한계
POP & Value in Project
Social Media
Model, View, Controller with POP & Value