You are here

Protocols

Some languages, such as C++, permit multiple inheritance. Objective-C does not support multiple inheritance, but it takes a safer approach by supporting protocols.

For Java developers, protocols are very similar to interfaces: A protocol is defined in a header file, and then implemented in an actual class. However, unlike Java, some of the methods in a protocol can be optional.

If an object supports all of the required components of a Protocol, then it "conforms" to that Protocol. This can be checked by using the 'conformsToProtocol' method.

In this example, I'll implement a Protocol named 'LiquidContainer'. (And since a marine gas can is a container of liquid, it will implement the protocol.)