什么是协议? [英] What is a Protocol?

查看:153
本文介绍了什么是协议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了文档,但仍然感到困惑.有人可以解释一下什么是协议吗? (您可以提供代码示例,但我确实在寻找解释)

I've read the documentation but I'm still confused. Can someone please explain what a protocol is? (You could give code examples but I'm really looking for an explanation)

推荐答案

这是一篇很棒的文章.实际上,Objective-C中的协议与Java中的接口或C ++中的纯虚拟类非常相似(尽管不完全一样,纯虚拟类可以具有数据成员...).基本上可以保证,特定的类知道如何响应给定的一组方法(消息).

Here's a great article on it. Effectively, a protocol in Objective-C is very similar to an interface in Java or a pure virtual class in C++ (although not exactly as pure virtual classes can have data members...). It's basically a guarantee that a specific class knows how to respond to a given set of methods (messages).

编辑,原始文章不见了,因此我将其替换为其他教程.

Edit The original article disappeared so I have replaced it with a different tutorial.

这篇关于什么是协议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆