Thursday, December 13, 2012

Object-Oriented Callback Design

Graham Lee:

Let’s gloss over, for a moment, the fact that simply setting this property triggers authentication. There are three things that could happen as a result of calling this method: two are the related ideas that authentication could succeed or fail (related, but diametrically opposed). The third is that the API needs some user input, so wants the app to present a view controller for data entry. Three things, one entry point. Which do we need to handle on this run? We’re not told; we have to ask. This is the antithesis of accepted object-oriented practice.

In this particular case, the behaviour required on event-handling is rich enough that a delegate protocol defining multiple methods would be a good way to handle the interaction.

Blocks are great, but I agree that Apple’s APIs don’t always use them properly.

Comments

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment