Home > Blogs > Cocoa Tip of the Day, 1/13/10

Cocoa Tip of the Day, 1/13/10

Plan for code reuse.

The loose coupling in Objective-C makes it very easy to reuse code.  If you use delegates, protocols, action methods, and key-value coding in a class, then it's easy to replace the classes that it interacts with.  Even if you don't think you will need to reuse a class, try to avoid tightly coupling it to the rest of your code.  You may find another use for it later, and it's better to use a class that you've already tested than to write a new one.

Cocoa Programming Developer's HandbookFor more tips, and more detail about this tip, please see my new book,
Cocoa Programming Developer's Handbook,
available in print and electronic formats.