Protocol Composition
Protocol inheritance is a powerful tool that lets you easily create a new protocol to add requirements to an existing protocol or set of protocols. Nevertheless, using protocol inheritance can potentially lead you to make poor decisions in creating your types.
In fact, that is exactly what has happened with TabularDataSource
when you made it inherit from CustomStringConvertible
because you wanted to be able to print a description of the data source.
(In fairness, you did it because we told you to.)
There is no correlation between the requirements of CustomStringConvertible
and TabularDataSource
, making them a poor candidate for inheritance. In a moment you will see how you can accomplish the same results without conflating ...
Get Swift Programming: The Big Nerd Ranch Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.