Design Patterns

A design pattern solves a common software engineering problem. Design patterns are not actual snippets of code, but instead are abstract ideas or approaches that you can use in your applications. Good design patterns are valuable and powerful tools for any developer.

The consistent use of design patterns throughout the development process reduces the mental overhead in solving a problem so you can create complex applications more easily and rapidly. Here are some of the design patterns that you have already used:

  • Delegation: One object delegates certain responsibilities to another object. You used delegation with the UITextField to be informed when the contents of the text field change.

  • Data source: A data source is similar to a delegate, but instead of reacting to another object, a data source is responsible for providing data to another object when requested. You used the data source pattern with table views: Each table view has a data source that is responsible for, at a minimum, telling the table view how many rows to display and which cell it should display at each index path.

  • Model-View-Controller: Each object in your applications fulfills one of three roles. Model objects are the data. Views display the UI. Controllers provide the glue that ties the models and views together.

  • Target-action pairs: One object calls a method on another object when a specific event occurs. The target is the object that has a method called on it, and the action is the method being called. For example, you used target-action pairs with buttons: When a touch event occurs, a method will be called on another object (often a view controller).

Apple is very consistent in its use of these design patterns, and so it is important to understand and recognize them. Keep an eye out for these patterns as you continue through this book; recognizing them will help you learn new classes and frameworks much more easily.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset