Protocol-oriented programming (POP) Swift मा behavior साझा गर्ने प्राथमिक तरिका हो: base class बाट inherit गर्नुको सट्टा, type हरू protocol conform गर्छन्, र protocol extension हरूले पुनः प्रयोगयोग्य default implementation दिन्छन्। यसले तपाईंलाई single inheritance को कठोरता बिना composition र code reuse दिन्छ।
यो कसरी काम गर्छ
Protocol ले requirement हरू घोषणा गर्छ; त्यो protocol माथिको extension ले default behavior दिन्छ जुन कुनै पनि conformer ले नि:शुल्क पाउँछ।
{
id: { }
}
{
name: { }
}
{
() -> { }
}
: , {
id:
name:
}
(id: , name: ).describe()
