|
The application Delicious Library gets top marks for its user-friendliness, its devoted adherence to the Macintosh human-interface guidelines, and its imaginative uses of Macintosh platform technologies—for example, its ability to use an iSight camera to scan an item into the applications database. However, Wil singles out one Apple technology, Cocoa bindings, as being central to his companys success so far. The value of Cocoa bindings, he says, is that, it makes it really easy for programmers to present data in a way thats very clear and intuitive to the user. It makes every app look and feel like an iApp. First Experiences with Cocoa BindingsWil was already working on Delicious Library when he found out about Cocoa bindings. But, being a leading edge kind of guy, he took time out to investigate. Wil says, I knew nothing about it; the technology had just come out, there were no experts in it. So I just went to the ADC site, read through the docs, compiled the sample code—the process just went so smoothly. Theres tutorials, theres tons of documents that give you a high-level overview—theres much more than could be in any book. And with intelligent searching, you can find just what you need. When I started reading about Cocoa Bindings, I was amazed at what it sounded like they could do. So we thought we would see how hard it would be to switch the code we had to use Cocoa bindings. We rewrote everything in a day or two—I think we deleted over a thousand lines of code that just wasnt needed any more. And when we got this new version working, it was doing more than the original version did. We found that the program just did multiple selections for free—and now, the delete function worked. How Cocoa Bindings WorkCocoa bindings is a collection of technologies—introduced in Mac OS X v10.3 Panther, and enhanced in Mac OS X v.10.4 Tiger—that enables you (among other things) to implement much of the necessary infrastructure of an MVC (Model-View-Controller) architecture by wiring Interface Builder objects to each other. At the lowest level, it enables you to synchronize two variables or object attributes within your program such that whenever one of them is changed (by either the user or the application), Mac OS X changes the other one automatically. By using Cocoa bindings in different ways, you can create a variety of useful automatic behaviors. For example, virtually every Cocoa application needs to keep two values synchronized—both a value in your programs model and the value for its on-screen representation. Before Cocoa bindings, Wil said, You were always trying to keep them in sync, but there was always the possibility that you had missed at least one place where a change in one value needed to be mirrored by a change in the other. As a result, the two values would wander out of sync. One of the basic things that Cocoa bindings give you for free is that they keep the on-screen controls exactly in sync with your data, and you dont have to say, Oh, wait a minute, I need to remember that if I update it here in my model data, I also have to update the control value. Live SearchingOne of the main features of Delicious Library is its ability to let you find specific items in your collection quickly and easily. Searching is a simple two-step process: select the media type (for example, music) in the left panel, then start typing whatever comes to mind (artist name, song title, genre, whatever) in the search field at the bottom. The more you type, the fewer items from your collection are displayed. Wil calls this feature live searching, and users absolutely love it. According to Wil, when you use Cocoa bindings to implement live searching, it takes about three lines of code to get the job done. Multiple SelectionsBy the way, Delicious Library doesnt artificially limit the research process to one kind of media at a time. You can search multiple categories (for example, books and music) by shift-clicking multiple categories before you begin typing in the search field. When you implement automatic behaviors using Cocoa bindings, your application automatically handles multiple selections. What is amazingly cool, Wil says, is that Cocoa bindings handle multiple selections really, really well—better than most programs ever do. Its so hard to do multiple selections correctly, but since Apple engineers were building it into the operating system, they decided to spend the time to do it right. When you use Cocoa bindings and configure them properly, you get another, more sophisticated multiple selection-related behavior—again, without writing any code. Delicious Library shows this behavior in action: When you select, for example, a Bob Marley CD from your collection, Delicious Library displays detailed information about that CD—artist name, CD title, a list of all the songs on the CD, and so on—in a detail panel on the right side of its window. When you select multiple CDs, however, what gets displayed depends on which CDs you selected. If both of them were recorded by Bob Marley, the artist field reads Bob Marley in black text, but if the CDs were recorded by different people, the same field reads different artists, this time in gray text. This is the kind of feature that makes the user say, Wow, this is a really great application—and Cocoa bindings makes this feature trivial to implement. Master-Detail InterfacesAnother place where youll commonly use Cocoa bindings, says Wil, is when you show users a list of items, and then they pick an item, and you show them more information about the item they picked. This is called a Master-Detail Interface, where the master interface contains a table view displaying your list of items, and the detail interface contains a view that displays more about the selected item. In Delicious Library, when you click on a CD or a book in the middle panel and Delicious Library tells you about it in the right panel, that happens just by using Cocoa bindings—and the delete key works, and multiple selections work, and you dont have to do anything extra to get all that. Cocoa Bindings as a Competitive AdvantageWil says that the concept behind Cocoa bindings is very powerful, and the more you understand it, the more uses you find for it. Its not just limited to the user interface, he says. Its about keeping objects in sync with each other. In addition to the features, polish, and reliability that have been added to Delicious Library through the use of Cocoa bindings, Wil acknowledges that Cocoa bindings also gave his company a significant competitive advantage. It enabled him to design, implement, and release a full-featured, innovative product in just under eight months, which works out to about eight person-months of programming effort. He adds, Without Cocoa bindings, it would have taken another four or five months, maybe more, to finish Delicious Library. And reducing your time-to-market by a full one-third is a competitive advantage that should make anybody take notice. For more information on Delicious Library, see the Delicious Monster website. |