Monday, October 12, 2009

Book Review: Cocoa Design Patterns

cdp.png The Cocoa Design Patterns Book is one I've been anticipating for a while now and the first Cocoa book i've gotten in my hands that I've been really excited to read (i just finally got Bill Dudneys iPhone SDK book and Marcus Zarra's Core Data Book after I already started reading this.) Mac & iPhone Developers face a unique challenge when learning Cocoa in that you are learning 2 things at once, an Object Oriented Language (Objective-C) and the Cocoa Frameworks. As Aaron Hillegass has stated, you can easily learn Objective-C in a couple hours no problem. It's the Cocoa Frameworks that present a challenge to developing a good Mac or iPhone App and that is what this book explains. It takes you through lots of things I see people ask about on the mailing lists like why we use
MyObject *object = [[MyObject alloc] init];
instead of
MyObject *object = [MyObject new];
Overall it has 32 chapters and covers 28 Design Patterns used throughout Cocoa. I particularly liked their approach of going through a design pattern and stating the motivation behind using it, how it works and then also stating the consequences of using the design pattern mentioned and, finally they provide an overview of some areas of Cocoa in which the Design Pattern is used. It leaves you feeling like they really spent a lot of time trying to provide an objective overview of all the design patterns they cover. You might get the impression at first that this is a book for beginners, but then you'd be completely wrong. In fact I don't really felt at any time during reading this book that it was dumbed down for beginners or mentioned topics way to advanced for newcomers to Cocoa. It really felt like just about any Cocoa Developer (even veterans) could pick this up, understand it, and immediately begin using the content in their apps. I learned many things from this book, it filled in some small holes in my knowledge of why some parts of Cocoa operate the way they do. I think this book fills in a really important gap in that we've had intro books for learning Mac or iPhone Development, and we've had advanced books on Mac Development and now we are getting books on various areas of how Core Animation, Core Data, etc work, but we haven't really had anything that sat you down and explained all the various design patterns employed by Cocoa and the other Mac/iPhone frameworks, and how they work in such detail before now. Additionally it provides source code for each design pattern, to not only explain how it works, but takes you through an example of the design pattern in action. It covers a lot of things from MVC to Singletons to Categories, Notifications, Delegates, The Responder Chain, Invocations, etc. About the only thing this book doesn't cover is multithreaded design patterns in Cocoa (that could practically be a book just by itself), and even though it was published after Snow Leopard came out, it was written with Leopard in mind. Given all the other great material it covers I think it's a fair trade off. They even do a good job as well mentioning areas where using Garbage Collection changes something in your code. They briefly mention blocks once, but didn't really say anything more about it, I had wished they'd at least mention it's a feature coming to Snow Leopard. Given when they intended to publish this book I can't say though that I blame them for briefly mentioning as they did. About the only thing I wish this book had is a PDF version of this book so that I could have it on reference on my Mac and search through it at any time like I can with the Pragmatic Programmer Books. Update: people have pointed out they do have a PDF available on the InformIT website link in the comments. The Verdict To say I really liked this book would be a tremendous understatement. In conclusion I think just about every Cocoa Developer out there should get this book, Apple should practically be giving this away with Developer Memberships, it's that good. It doesn't matter if your using Cocoa for the Mac or iPhone, this book is something you should have, the material applies just as well to either area of development. Trust me, you'll be glad you got this book. It really gets you thinking about the design patterns you use in your own code, and how you could design your apps better. I know because it's already got me thinking more about the design patterns I use in my own projects.

8 comments:

  1. InformIT has a PDF version for sale. In fact, I just left a medium-sized rant for their support staff, since buying the book (and creating the requisite account with which to do so) was trip through web form usability hell. It was pushy and "wrong" in almost every conceivable sense.

    I haven't yelled so much at my computer screen while buying something in years.

    ReplyDelete
  2. That's news to me. The back of the book shows a Safari subscription which gives you access to it for 45 days after which I assume you have to pay. If they do have a PDF version for sale I'd wish they'd let you know about it.

    ReplyDelete
  3. Anonymous9:57 AM

    The link to the pdf versions of the book is:

    http://www.informit.com/store/product.aspx?isbn=0321591194

    I am off to get it now!

    ReplyDelete
  4. I just bought the PDF version. Thanks for pointing it out. I agree 100% with the comment above: the informit website is a usability disaster...

    ReplyDelete
  5. Anonymous4:12 PM

    Can you open the PDF version in something other than Adobe Reader?

    ReplyDelete
  6. Stuart Dootson9:31 AM

    Woot - it's on Safari - that's me sorted, as I have a subscription :-)

    ReplyDelete
  7. Thanks for your sharing, it helps a lot.

    ReplyDelete
  8. Thx, i also have this book but haven't finished it. Anyway, you are my paragon who i always learn from. Keeping up~~

    ReplyDelete