Chapter 4: Hold On Loosely: Cocoa Design Patterns
If you’re like most iOS developers, Objective-C is not your first language. You probably have a background in other object-oriented languages like Java, C++, or C#. You may have done development in C. None of these languages really prepare you for how to think in Objective-C.
In the beginning there was Simula, and Simula had two children: C++ from Bell Labs and Smalltalk from Xerox PARC. From C++ sprung Java, which tried to make things easier. Microsoft wrote Java.NET and called it C#. Today, most developers are trained in this branch of Simula. Its patterns include generic programming, static typing, customization through subclassing, method calling, and strong object ownership.
Objective-C and Cocoa come from the Smalltalk fork. NeXT developed a framework called NeXTSTEP. It was written in Objective-C and implemented many of Smalltalk’s patterns. When Apple brought NeXTSTEP to the Mac, it renamed it Cocoa, although the NS
prefix remains to this day. Cocoa has very different patterns, and this is what sometimes gives new developers trouble. Common Cocoa patterns include protocols, dynamic typing, customization through delegation, message passing, and shared object ownership.
I’m not going to give a computer science history lesson here, but it’s important to understand that Objective-C is not Java and it’s not C++. It’s really Smalltalk. Because few developers learn Smalltalk, most need to adjust their thinking to get the most ...