The protocol can be understood as what is commonly called an interface. Through the protocol, some design patterns can be implemented in a standardized manner and improve the efficiency of development.
Personally, I feel that many functions of OC exist like patches. Sometimes in order to add an effect, you need to create a new set of grammar rules to use it.
The introduction of protocol is quite useful. The simplest one is to implement event delegation (delegate) In addition, multiple delegates can be implemented but only one class can be inherited
For example, the UITableViewDelegate and UITableViewDataSource owned by TableView in UIKit allow you to easily use a class as the data source of the view without having to inherit a class, which means you can use UIViewController as the data source
To put it more broadly, interface-oriented programming can decouple object events. Objects rely on interfaces rather than the specific implementation of objects. This is very powerful for team development and code maintenance.
The protocol can be understood as what is commonly called an interface. Through the protocol, some design patterns can be implemented in a standardized manner and improve the efficiency of development.
Personally, I feel that many functions of OC exist like patches. Sometimes in order to add an effect, you need to create a new set of grammar rules to use it.
The introduction of protocol is quite useful. The simplest one is to implement event delegation (delegate)
In addition, multiple delegates can be implemented but only one class can be inherited
For example, the UITableViewDelegate and UITableViewDataSource owned by TableView in UIKit allow you to easily use a class as the data source of the view without having to inherit a class, which means you can use UIViewController as the data source
To put it more broadly, interface-oriented programming can decouple object events. Objects rely on interfaces rather than the specific implementation of objects. This is very powerful for team development and code maintenance.