Issues and alternatives

Implementation inheritance is controversial among OOP programmers and theoreticians. For instance, the authors Erich Gamma, John Vlissides, Ralph Johnson, and Richard Helm, of the book Design Patterns: Elements of Reusable Object-Oriented Software, advocate interface inheritance instead of implementation inheritance and recommend preferring composition over inheritance.

For example, the decorator pattern (as stated previously) has been proposed to overcome the static nature of inheritance between classes.

Furthermore, the OOP community agrees that inheritance introduces unnecessary coupling and breaks encapsulation, so modifications to the super classes can cause undesirable behavioral changes in subclasses.

In Swift, the usage of protocols and extensions is encouraged. Using protocols avoids the coupling problem because no implementation is shared. We will talk more about protocols and protocol extensions in the POP section of this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset