Protocol-oriented programming (POP) is Swift's preferred way to share behavior: instead of inheriting from a base class, types conform to protocols, and protocol extensions supply reusable default implementations. This gives you composition and code reuse without the rigidity of single inheritance.
How it works
A protocol declares requirements; an extension on that protocol provides default behavior any conformer inherits for free.
{
id: { }
}
{
name: { }
}
{
() -> { }
}
: , {
id:
name:
}
(id: , name: ).describe()
