Protocol-oriented programming (POP) என்பது behavior-ஐ பகிர்ந்துகொள்ள Swift விரும்பும் வழி: ஒரு base class-லிருந்து inherit செய்வதற்குப் பதிலாக, type-கள் protocol-களை conform செய்கின்றன, மேலும் protocol extension-கள் மறுபயன்பாட்டு default implementation-களை வழங்குகின்றன. single inheritance-இன் விறைப்பு இல்லாமல் இது உங்களுக்கு composition மற்றும் code reuse-ஐ அளிக்கிறது.
இது எப்படி வேலை செய்கிறது
ஒரு protocol requirement-களை declare செய்கிறது; அந்த protocol மீதான ஒரு extension எந்தவொரு conformer-உம் இலவசமாக inherit செய்யும் default behavior-ஐ வழங்குகிறது.
{
id: { }
}
{
name: { }
}
{
() -> { }
}
: , {
id:
name:
}
(id: , name: ).describe()
