I think...
1: Informal protocol - I don't really see any advantage of doing this over a formal protocol.
2: Passing SELs - I don't think this is an established pattern in Cocoa. I personally wouldn't consider it as better than the delegate approach, but if it fits your thinking better, then go for it. You're not really getting rid of state; you're just transforming into something else. Personally, I'd prefer to have an ivar that I can set and check without having to use selector types.
3: Passing blocks - This is sort of a new-age approach, and it has some merit. I think you need to be careful though because, in my opinion, it doesn't scale really well. For example, if NSTableView's delegate and data source methods were all blocks, I would personally find that somewhat annoying. Imagine if you wanted to set 10 different blocks, your -awakeFromNib (or whatever) method would be pretty big. Individual methods seem more appropriate in this case. However, if you're sure that you're never going to go beyond, say, two methods, then the block approach seems more reasonable.
Welcome to discuss. :D
相关帖子
- 新西兰不为人知的另一面:分享一个有关留学和移民失败的案例
- 在新加坡做面试官的经历 (Interviewer Experience for UI/UX Designer in Singapore)
- 刷Leetcode (01) Remove Duplicates from Sorted Array
- 我有个刚会走路的孩子。她应该如何准备去应对15年后的人工智能的世界的职场?我应该在她肯学的时候就开始教她Python么?
- 大早上打扰了,请教审核问题 3.1: Apps or metadata that mentions the name of any other mobile platform will be rejected