Where to go from here?

Protocols and protocol oriented programming are at the foundation of the Swift language. The generics system, for example, uses protocols to specify with precision the type requirements of a generic type in use. If have M data structures and N algorithms that operate on those data structures. With some languages, you need M*N blocks of code to implement them. With Swift, using protocols you only need to write M+N things with no repetition. Only exactly what you need. Protocol- oriented programming gives you all of the advantages of typical object-oriented programming while dodging most of the pitfalls.

Next time you are faced with a programming task, see if you can figure out the underlying protocols at play. Doing so will lead you to a more flexible and extensible solution. Initially you might find it easier to get something concrete working first and then extract the protocols. As you get more experienced, however, you may start seeing the protocols before you even begin coding just as easily as Neo can see the red dress. :]

results matching ""

    No results matching ""