6. Category
The Category pattern adds methods to existing classes and provides an alternative to subclassing in many situations. The Category pattern is supported directly by the Objective-C language and is used extensively in the implementation of other Cocoa design patterns. The added methods are inherited by all subclasses of the extended class and are indistinguishable at runtime from methods originally compiled into the class.
The Category pattern can also be used to replace the implementations of methods in existing classes, perhaps to fix bugs in framework classes without needing source code for those classes. However, there is no convenient way to call the original method from the code that replaces it. When replacing a method, you must ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access