Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

1.7. Design Patterns

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.

Fig. 1.8. Design patterns used in iPhone for Programmers.
Design PatternWhere it’s usedHow it’s used
Abstract FactoryIntroduced 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 ResponsibilityIntroduced in Chapter 7’s Spot-On app; seen in several later apps.Built into Cocoa as the mechanism for dealing with events.
CommandIntroduced 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.
CompositeIntroduced 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.
DecoratorIntroduced in Chapter 6’s Flag Quiz app; used in most later apps.To add new functionality to an existing class without subclassing.
FacadeIntroduced in Chapter 6’s Flag Quiz app.To provide a simple interface for the behaviors of a complex subsystem.
Model View ControllerIntroduced 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).
MementoIntroduced 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”).
SingletonIntroduced 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 MethodsIntroduced 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.



  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial