哪个更好 - 依赖委托还是通过对象持久化 - iOS

发布于 2024-10-02 14:02:21 字数 216 浏览 0 评论 0原文

经过一番阅读后,我注意到苹果公司推动在控制器上使用委托来相互通信。

假设我有一个菜单控制器,需要与帮助控制器进行通信(并且它们需要共享信息 - 哈哈,不要问我为什么要共享信息)。我可以通过委托来完成此操作,但是当我可以通过帮助对象传递所需信息并让帮助控制器拾取在前一个控制器中更改的信息时,为什么要使用委托呢?

代表仍然是成对的——无论它有多松散,使用对象难道不是可重用性的最佳实践吗?

After doing some reading I notice Apple pushes the use of delegates on controllers communicating with one another.

So say I have a Menu controller which needs to communicate with the help controller (and they need to share info - lol don't ask me why they would). I could do this through delegates, but why use delegates when I can pass the required information on through a help object and have the help controller pick back up this info that was changed in the previous controller.

Delegates still couples - however loosely it may be, wouldn't the use of objects be the best practice here for re usability?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸印温柔 2024-10-09 14:02:21

代表对于响应非常有用,尤其是在不会立即响应的情况下。

如果您只是告诉帮助控制器要显示哪些信息之类的信息,那么直接传递它就很好。例如,如果您想知道帮助控制器何时完成向用户显示帮助,则委托会更清晰且通常更优越。

Delegates are great for responses, especially if the response isn't going to be immediate.

If you're simply telling the help controller something like what information to display, passing it directly is great. If you want to know, for example, when the help controller is done displaying help for the user a delegate is clearer and usually superior.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文