recursion (recurse) wrote in ood,

  • Music:


Lately I've been finding myself less and less interested in MVC. It's a good pattern, a useful pattern, and definitely the sort of thing one wants to make use of (especially if it's used by one's framework-of-choice, like Cocoa), and I doubt I'm going to be giving it up. It's just not interesting to me any more.

What is interesting (for the moment) is the addition of filters to the mix. Filters are short-lived objects which serve to transform one kind of value to another kind, or perform some other transformation. You don't necessarily have to have them as objects; methods (perhaps added by a category) are just as worthy of the name. Regardless, the mechanism is less interesting than the filtering itself.

Mac OS X 10.3 adds a system of bindings to Cocoa which let you do a lot of UI updating (and the like) via Interface Builder. They provide classes like NSObjectController, NSArrayController, and NSUserDefaultsController to let you bind values to arbitrary objects. For instance, you can connect an NSArrayController to e.g. an array owned by a custom view object, and then bind a table view to the array controller to list the items in the view, all without adding any further code.

Of course, you're not always going to have values in the format you want. Because of this, we've got a set of subclasses of NSValueTransformer which provide an interface for transforming arbitrary values, and sometimes for transforming them back again.

It's not the first time filter objects have been used, but it's a good example of how they can be put to use to good effect. Personally, my favourite transformer is the NSUnarchiveFromDataTransformer; using it and the controller layer, I made a small program without writing any code at all. That's more of a testament to Interface Builder than to filters in general, but nonetheless, they're a good pattern to put to good use.

Now if only Objective-C/Cocoa had lexical closures...
  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.