Protocol-oriented programming (POP) એ behavior share કરવાની Swift ની પસંદગીની રીત છે: base class થી inherit કરવાને બદલે, type protocol ને conform કરે છે, અને protocol extension ફરીથી વાપરી શકાય તેવા default implementation પૂરા પાડે છે. આ તમને single inheritance ની કઠોરતા વગર composition અને code reuse આપે છે.
તે કેવી રીતે કામ કરે છે
Protocol requirement declare કરે છે; તે protocol પરનું extension default behavior પૂરું પાડે છે જે કોઈપણ conformer મફતમાં inherit કરે છે.
{
id: { }
}
{
name: { }
}
{
() -> { }
}
: , {
id:
name:
}
(id: , name: ).describe()
