iOS/iOS Swift Udemy - AngelaYu

Section13. 145) Protocol

Developer-Michelle 2022. 12. 13. 18:12

Section13. 145) Protocol

17분 12초

 

 

Protocol

class Bird ->Eagles :CanFly

                  ->Penguins

struct Airplane :CanFly

 

Protocol: 마치 자격증과 같은거.

 

Bird  - layEggs(), .... 안에 함수가 여러개 있으나 이걸 Penguins이 그대로 상속받을 경우 날지 못하는데 fly함수까지 받아버리므로... 

이런 경우 penguins 의 기능에 해당하는 함수들을 Bird안에 구현해서

CanFly는 따로 프로토콜로 채택해주는 식으로.