Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Besides using predefined objects in your code, you’ll also use several predefined design patterns[4] to help you design and implement your apps according to Apple’s guidelines (Fig. 1.8). Like a pattern a dressmaker uses to create clothing, a design pattern provides programmers with an architectural template for designing and implementing apps.
[4] Some books you’ll want to consult on design patterns are the seminal “gang of four” book, Design Patterns: Elements of Reusable Object-Oriented Software, by Gamma, Helm, Johnson and Vlissides, ©1994, Addison Wesley, and Cocoa Design Patterns, by Buck and Yacktman, ©2010, Addison Wesley.
| Design Pattern | Where it’s used | How it’s used |
|---|---|---|
| Abstract Factory | Introduced in Chapter 4’s Tip Calculator app; used in every later app. | Many Foundation framework classes (Fig. 1.9) allow programmers to use one familiar interface to interact with different data structures. |
| Chain of Responsibility | Introduced in Chapter 7’s Spot-On app; seen in several later apps. | Built into Cocoa as the mechanism for dealing with events. |
| Command | Introduced in Chapter 5’s Favorite Twitter Searches app; used in most later apps. | To bind GUI components to actions (i.e., event handlers) that are triggered in response to events. |
| Composite | Introduced in Chapter 5’s Favorite Twitter Searches app; used in most later apps. | To create a hierarchy of objects that can all be manipulated through the root object. |
| Decorator | Introduced in Chapter 6’s Flag Quiz app; used in most later apps. | To add new functionality to an existing class without subclassing. |
| Facade | Introduced in Chapter 6’s Flag Quiz app. | To provide a simple interface for the behaviors of a complex subsystem. |
| Model View Controller | Introduced in Chapter 4’s Tip Calculator app; used in every later app. | To separate app data (contained in the model) from graphical presentation (the view) and input-processing logic (the controller). |
| Memento | Introduced in Chapter 5’s Favorite Twitter Searches app; used in every later app that needs to save data. | To represent an object as a bit stream so it can be saved to a file or transferred over a network (also called “serialization”). |
| Singleton | Introduced in Chapter 5’s Favorite Twitter Searches app. | To ensure that only one object of a class is created. Other objects in the app can share the singleton object. |
| Template Methods | Introduced in Chapter 4’s Tip Calculator app; used in every later app. | To define an algorithm in a superclass, parts of which a subclass can override. |