Protocol Composition

Protocol inheritance is a powerful tool that lets you easily create a new protocol that adds 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. You made TabularDataSource 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.) But there is not anything inherently CustomStringConvertible about a tabular data source. Go back and fix that misguided attempt to print data sources.

Listing 19.14  TabularDataSource should not be ...

Get Swift Programming: The Big Nerd Ranch Guide 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.