Protocol-oriented programming (POP) हा Swift चा behavior शेअर करण्याचा पसंतीचा मार्ग आहे: base class कडून inherit करण्याऐवजी, types protocols ला conform करतात, आणि protocol extensions पुन्हा वापरता येण्याजोग्या default implementations पुरवतात. यामुळे तुम्हाला single inheritance च्या कठोरतेशिवाय composition आणि code reuse मिळते.
हे कसे कार्य करते
एक protocol requirements declare करते; त्या protocol वरील एक extension default behavior पुरवते जे कोणताही conformer मोफत inherit करतो.
{
id: { }
}
{
name: { }
}
{
() -> { }
}
: , {
id:
name:
}
(id: , name: ).describe()
