Skip to content

Instantly share code, notes, and snippets.

@torpedo87
Created March 30, 2019 03:12
Show Gist options
  • Save torpedo87/36e848659fffc4c96fbc50225eca3577 to your computer and use it in GitHub Desktop.
Save torpedo87/36e848659fffc4c96fbc50225eca3577 to your computer and use it in GitHub Desktop.
protocol oriented programming

static dispatch

  • 컴파일 시 찾기
  • 빠르다
  • 프로토콜 자체에 익스텐션으로 이미 구현되어 있는 메소드

dynamic dispatch

  • 런타임 시 v-table 을 통해서 찾기
  • 프로토콜을 준수하기 때문에 컴파일 되나, 내부의 구현 내용은 런타임에 알 수 있다

message dispatch

  • objective-c 런타임이 사용
  • 런타임시 유동적
  • @objc func

OOP

  • 하나의 클래스만 상속가능
  • 메모리 레이아웃도 따라서 상속됨
  • 레퍼런스 타입

V-table

  • 각 클래스는 하나의 V table 을 갖고 있다
  • 객체지향에서는 상속을 하기 때문에 메소드 호출시 해당 메소드가 어느 클래스에 있는 것인지를 찾는 과정(dispatch)이 필요하다

POP

  • 청사진일 뿐
  • 다수의 프로토콜을 준수할 수 있다
  • 메모리 레이아웃에 제한이 없다
  • retroactive modeling

protocol witness table

  • 각 타입은 여러개의 protocol witness table을 가질 수 있다
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment