-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
๐๐ปโโ๏ธย 10-2 : Protocol Oriented Programming๊ณผ Object Oriented Programming์ ์ฐจ์ด์ ์ ์ค๋ช ํ์์ค.
- Object Oriented Programming(OOP, ๊ฐ์ฒด์งํฅ ํ๋ก๊ทธ๋๋ฐ)์ย
ํด๋์ค๋ฅผ ์ค์ฌ์ผ๋ก ์ค๊ณ๋๋ฉฐ,
์์(Inheritance)์ ํ์ฉํ์ฌ ์ฝ๋๋ฅผ ์ฌ์ฌ์ฉํ๊ณ ํ์ฅํ ์ ์์ต๋๋ค.
ํด๋์ค ๊ธฐ๋ฐ ์ค๊ณ์์๋ ๋ถ๋ชจ ํด๋์ค์ ์์ฑ๊ณผ ๋ฉ์๋๋ฅผ ์์ ํด๋์ค๊ฐ ์์๋ฐ์ ํ์ฅํ ์ ์์ต๋๋ค.
์๋ฅผ ๋ค์ด,ยAnimalย ํด๋์ค๋ฅผ ์์๋ฐ๋ยDog,ยCatย ํด๋์ค๊ฐ ๊ฐ๊ฐ์ ํน์ฑ์ ์ถ๊ฐํ๋ ๋ฐฉ์์ ๋๋ค. - Protocol Oriented Programming(POP, ํ๋กํ ์ฝ ์งํฅ ํ๋ก๊ทธ๋๋ฐ)์ย
ํ๋กํ ์ฝ(Protocol)์ ์ค์ฌ์ผ๋ก ์ค๊ณ๋๋ฉฐ,
๊ตฌ์กฐ์ฒด(Struct)์ ํ๋กํ ์ฝ ํ์ฅ(Protocol Extension)์ ์ ๊ทน์ ์ผ๋ก ํ์ฉํ์ฌ ์ฝ๋๋ฅผ ํ์ฅํ ์ ์์ต๋๋ค.
Swift๋ ๊ตฌ์กฐ์ฒด์ ํ๋กํ ์ฝ ํ์ฅ์ ํตํด ๋ค์ค ์์์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ณ , ํ์ ์ ๋ ์ ์ฐํ๊ฒ ์ค๊ณํ ์ ์๋๋ก ๋์ต๋๋ค. - OOP์์๋ย ํด๋์ค ๊ณ์ธต ๊ตฌ์กฐ๋ฅผ ์ค๊ณํด์ผ ํ์ง๋ง,
POP์์๋ย ์ฌ๋ฌ ๊ฐ์ ํ๋กํ ์ฝ์ ์กฐํฉํ์ฌ ๊ธฐ๋ฅ์ ํ์ฅํ ์ ์์ต๋๋ค.
์ด๋ก ์ธํดย ๋ ์ ์ฐํ๊ณ , ๋จ์ผ ์์์ ํ๊ณ๋ฅผ ๊ทน๋ณตํ ์ค๊ณ๊ฐ ๊ฐ๋ฅํฉ๋๋ค. - Swift๋ ํ๋กํ ์ฝ ์งํฅ ์ธ์ด๋ก ์ค๊ณ๋์์ผ๋ฉฐ,
๊ธฐ๋ณธ ํ์ ์ธยInt,ยString,ยArrayย ๋ฑ๋ ๊ตฌ์กฐ์ฒด(Struct)๋ก ๊ตฌํ๋์ด ์์ต๋๋ค.
์ฆ,ย ํด๋์ค๊ฐ ์๋ ๊ตฌ์กฐ์ฒด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ๋กํ ์ฝ์ ํ์ฉํ์ฌ ๊ธฐ๋ฅ์ ํ์ฅํ๋ ๊ฒ์ด Swift์ ์ฒ ํ์ ๋๋ค. - OOP์ ๋จ์ ย ์ค ํ๋๋ย ํด๋์ค ๊ณ์ธต ๊ตฌ์กฐ๊ฐ ๊น์ด์ง๋ฉด ์ ์ง๋ณด์๊ฐ ์ด๋ ค์์ง๋ค๋ ์ ์
๋๋ค.
POP์ ํ์ฉํ๋ฉดย ๋ค์ค ํ๋กํ ์ฝ์ ์กฐํฉํ์ฌ ์ฝ๋์ ๊ฐ๋ ์ฑ๊ณผ ์ฌ์ฌ์ฉ์ฑ์ ๋์ผ ์ ์์ผ๋ฉฐ,
๊ตฌ์กฐ์ฒด๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ ํ์ (Value Type)์ ์ฅ์ ๋ ์ด๋ฆด ์ ์์ต๋๋ค..
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels