Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol Oriented Programming과 Object Oriented Programming의 차이점을 설명하시오. #28

Open
dailynj opened this issue Nov 19, 2021 · 4 comments
Labels

Comments

@dailynj
Copy link
Contributor

dailynj commented Nov 19, 2021

No description provided.

@dailynj dailynj added the Swift label Nov 19, 2021
@co3oing
Copy link
Member

co3oing commented Nov 22, 2021

Protocol Oriented Programming은 프로토콜 중심 프로그래밍, Object Oriented Programming은 객체 중심 프로그래밍입니다.
POP는 프로토콜 확장을 통하여 수평 구조로 타입을 확장하고, OOP는 슈퍼클래스의 상속을 통하여 수직 구조로 타입을 확장하는 방식으로 다형성을 구현 합니다.

@dailynj
Copy link
Contributor Author

dailynj commented Nov 22, 2021

OOP(Object Oriented Programming)은 객체중심 프로그래밍으로, 상속을 통해 타입을 확장하는 수직적인 구조를 가지고 있습니다. 그렇기때문에 슈퍼클래스를 그대로 상속받아 필요없는 메소드와 변수를 모두 물려받아야한다는 단점이 있습니다. 또한 상속구조를 사용하기위해서는 value type으로 정의해도 되는 모델들을 reference 타입으로 정의해야하는 불편함이 있습니다.

POP(Protocol Oriented Programming)은 프로토콜 중심 프로그래밍으로, 슈퍼클래스와 서브클래스의 사이가 독립적이고 reference 타입과 value 타입을 모두 지원하여 OOP의 단점들을 모두 보완한다고 말할 수 있습니다. 또한, 합성으로 객체를 묘사하는 수평적인 구조를 가지고 있어 상속과는 다르게 다수의 프로토콜을 가지는 것이 가능합니다.

@inuinseoul
Copy link
Collaborator

OOP는 상속을 기본 전제로 가져가기 때문에 Super Class와 Sub Class가 생성됩니다. 이 때 Sub Class는 Super Class를 그대로 상속받기 때문에 자신에게 필요하지 않은 property나 method를 가질수 없습니다. 하지만 POP는 protocol에 정의된 인터페이스를 직접구현하는 것이 전제입니다. 따라서 필요하지 않은 property나 method를 갖지 않도록 구현할 수 있습니다. 또한 상속에서는 하나의 Sub Class는 하나의 Super Class만을 가질 수 있지만 Protocl은 그렇지 않습니다.

@duyeonnn
Copy link
Collaborator

OOP의 핵심은 상속입니다. 상속을 통해 타입을 확장하는 수직 구조이고 IS-A 관계를 표현 할 수 있습니다. 이 과정에서 불필요한 메서드나 변수를 물려 받아야 한다는 단점이 있고 class에서만 상속이 가능합니다.

POP는 수평구조 표현인 합성으로 객체를 묘사할 수 있게 도와줍니다. 합성을 통해 타입을 확장하고 HAS-A 관계로 표현됩니다. Protocol은 불필요한 메서드나 변수를 갖지 않게 할 수 있고 class 뿐만 아니라 struct, enum에서도 사용 가능합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants