Protocol-oriented programming (POP) అనేది behavior ను share చేయడానికి Swift యొక్క ఇష్టమైన మార్గం: ఒక base class నుండి inherit చేయడానికి బదులుగా, type లు protocol లకు conform అవుతాయి, మరియు protocol extension లు reusable default implementation లను సరఫరా చేస్తాయి. ఇది single inheritance యొక్క దృఢత్వం లేకుండా మీకు composition మరియు code reuse ను ఇస్తుంది.
ఇది ఎలా పనిచేస్తుంది
ఒక protocol requirement లను declare చేస్తుంది; ఆ protocol పై ఒక extension ఏ conformer అయినా ఉచితంగా inherit చేసే default behavior ను అందిస్తుంది.
{
id: { }
}
{
name: { }
}
{
() -> { }
}
: , {
id:
name:
}
(id: , name: ).describe()
