代表们 - 他们真的很重要吗? [英] Delegates - What are they REALLY?

查看:106
本文介绍了代表们 - 他们真的很重要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以使用类似于某些现实生活中的过程来解释他们,例如运行棒球队,咖啡店或汽车机械店 - 任何会感觉到的东西?
喜欢不用说CODE或SYNTAX或编程 - 我看过很多帖子,没有人真的为我做这件事 - 我们可以先谈论概念吗?



喜欢我甚至不明白为什么我们有他们,他们如何有利等等。



告诉我真实世界的类比一个流程运行有和没有代表,所以我可以看到什么使他们如此有用和伟大。



然后我们可以编码出来。



(而且,我的具体兴趣是在Objective-C / iPhone应用开发实现中 - 但我真的认为,首先理解这个概念更重要。)



提前谢谢

解决方案


他们真的吗?


专家






客户:你修好了我的车吗?



员工:我估计我们有机会在不到一个小时内看。客户:我已经等了30分钟,我真的很仓促!



员工:我们在一年的这个时候很忙碌。



客户:你不会似乎忙;你一直在前台!



员工:我不是技工。我是经理。你还要我修理你的刹车吗?






经理擅长他做什么;他详细说明了客户的问题,订购指示灯,制定时间表,并做了工资。虽然他喜欢汽车,对他们很了解,但他不是修理他们的专家。经理有能力在商店做很多事情,但是修理客户制动所需的专业技术。



使用最常见的原因之一是避免子类化(这就像发送经理到学校成为一个技工 - 一个看起来很像多重继承的类比)。当子类化可以用于专门化时,通常可以使用委托。代表团是一个松散的债券,在一个好的设计中,一个对象履行了所有或大部分的职责,但是经常将其职责的专门部分留给其他实施(代表)。


Can anyone out there explain them using analogies to some real-life processes - like running a Baseball team, or a coffee shop, or an Auto-Mechanic's Shop - anything that would MAKE SENSE? Like lets not even talk CODE, or SYNTAX, or programming - I've seen plenty of those posts and none of them really do it for me - can we just talk concepts first?

Like I don't even understand WHY we have them, how they're advantageous, etc.

Show me the real-world analogy of a process run with and without delegates, so I can see what makes them so useful and great.

Then we can code-it-out.

(And FYI, my specific interest is in Objective-C/iPhone App Development implementation - but I really think understanding this conceptually first is much more important.)

thanks in advance!

解决方案

What are they REALLY?

specialists


Customer: Hi - did you fix my car?

Employee: I estimate that we'll have a chance to look at it in less an hour. I'll call you when it's ready.

Customer: I've already waited 30 minutes, and I'm really in a rush!

Employee: We're very busy at this time of year.

Customer: You don't seem busy; you've been at the front desk the entire time!

Employee: I'm not a mechanic. I am the manager. Do you still want me to fix your brakes?


The manager's good at what he does; he details problems for the customers, orders blinker fluid, makes the schedule, and does payroll. Although he likes cars and knows a lot about them, he's not a specialist at repairing them. The manager's capable of doing many things at the shop, but it's the mechanics that have the expertise required to fix the customer's brakes.

One of the most common reasons delegation is used is to avoid subclassing (that would be like sending the manager to school to become a mechanic - an analogy which looks a lot like multiple inheritance). When subclassing could be used to specialize, delegation may often be used instead. Delegation is a looser bond where (in a good design) one object fulfills all or most of the duties, but leaves frequently specialized portions of its duties to other implementations (the delegates).

这篇关于代表们 - 他们真的很重要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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