Protocol
A protocol is not itself a class. Rather, it's an interface that declares methods. Only the methods are declared, that is, there is no body of the method defined in the protocol. The reason that format protocols are used for the delegation pattern is two fold:
1. The protocol acts as a documentation of the delegate interface and it allows for the compiler to check adherence.
2. At runtime you can interrogate an object in a single call to see if a protocol has been adopted rather than checking on a per method basis to see if an object will respond to a message.
The delegates are responsible for implementing the methods of the confirming protocol.
Implementing the Strategy pattern
To work with a protocol, we need to:
1. Define the protocol
2. Create the delegate property
3. Declare the protocol methods
Defining the protocol
A protocol is defined by using the @protocol
compiler directive, combined with an @end
directive. In between the two directives, we must declare the protocol method...