As someone who is becoming more comfortable working in Objective-C I would like to be able to incorporate more design patterns and OOP features in my projects but struggle to implement them as required by GoF because you cannot create an abstract class. I want to 1) avoid lots of subclassing, 2) minimize use of
conformsToProtocol, etc, 3) avoid techniques like
swizzling as much as possible, 4) maximize encapsulation, and 5) avoid long conditionals or lots of
For example, in a recent project I wanted to separate
RestKit (a library for accessing RESTful services) from my
UIViewController subclasses. I did so by incorporating an
Adapter between the two with a base class of
ModelController, which could access models. I also created the
ModelControllerDelegate protocol for my VC's to wire up. But I experienced great difficulty in creating a
ModelControllerDecorator without the use of an abstract base class. I wanted to be able to decorate my
ModelController with different aspects, like
QueryableDecorator, and so forth.
I've heard that using Objective-C++ is one way to incorporate more OOP features, but how about using standard Objective-C language features? How have you been able to incorporate GoF design patterns that use C++ style features (like
virtual classes) in your projects?