Cocoa Design Patterns. Erik M. Buck October 17, 2009

Similar documents
Design Patterns. Gunnar Gotshalks A4-1

Topics in Object-Oriented Design Patterns

Software Engineering - I An Introduction to Software Construction Techniques for Industrial Strength Software

Design Patterns Design patterns advantages:

Design Patterns. An introduction

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Using Design Patterns in Java Application Development

Design Patterns. CSC207 Fall 2017

Idioms and Design Patterns. Martin Skogevall IDE, Mälardalen University

ADAPTER. Topics. Presented By: Mallampati Bhava Chaitanya

Lecture 13: Design Patterns

Pattern Resources. Lecture 25: Design Patterns. What are Patterns? Design Patterns. Pattern Languages of Programming. The Portland Pattern Repository

Design Patterns. CSC207 Winter 2017

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

Patterns for Decoupling

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

Goals of Lecture. Lecture 27: OO Design Patterns. Pattern Resources. Design Patterns. Cover OO Design Patterns. Pattern Languages of Programming

An Introduction to Patterns

Design Patterns. CSC207 Fall 2017

Object-Oriented Design

Chapter 12 (revised by JAS)

Patterns of learning

Design Patterns. Observations. Electrical Engineering Patterns. Mechanical Engineering Patterns

Crash course on design patterns

Introduction to Software Engineering

SOFTWARE PATTERNS. Joseph Bonello

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.

Review Software Engineering October, 7, Adrian Iftene

Facade and Adapter. Comp-303 : Programming Techniques Lecture 19. Alexandre Denault Computer Science McGill University Winter 2004

Applying the Observer Design Pattern

Tuesday, October 4. Announcements

LECTURE NOTES ON DESIGN PATTERNS MCA III YEAR, V SEMESTER (JNTUA-R09)

An Introduction to Patterns

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

James Newkirk

Advanced Object Oriented PHP

CHAPTER 6: CREATIONAL DESIGN PATTERNS

Introduction to Testing and Maintainable code

Trusted Components. Reuse, Contracts and Patterns. Prof. Dr. Bertrand Meyer Dr. Karine Arnout

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Ingegneria del Software Corso di Laurea in Informatica per il Management. Design Patterns part 1

Applying the Decorator Design Pattern


C++ INTERFACE CLASSES STRENGTHENING ENCAPSULATION

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

CSC7203 : Advanced Object Oriented Development. J Paul Gibson, D311. Design Patterns

INTERNAL ASSESSMENT TEST III Answer Schema

SOFTWARE ENGINEERING SOFTWARE DESIGN. Saulius Ragaišis.

Design patterns. Valentina Presutti courtesy of Paolo Ciancarini

Chapter 10: Performance Patterns

Plan. Design principles: laughing in the face of change. What kind of change? What are we trying to achieve?

MVC. Model-View-Controller. Design Patterns. Certain programs reuse the same basic structure or set of ideas

PATTERNS AND SOFTWARE DESIGN

Outline. Design Patterns. Observer Pattern. Definitions & Classifications

CPSC 310 Software Engineering. Lecture 11. Design Patterns

Coordination Patterns

DESIGN PATTERN - INTERVIEW QUESTIONS

Applying Design Patterns to accelerate development of reusable, configurable and portable UVCs. Accellera Systems Initiative 1

Recitation 13. Software Engineering Practices and Introduction to Design Patterns

The Software Design Process. CSCE 315 Programming Studio, Fall 2017 Tanzir Ahmed

Lecture 4: Design Concepts For Responsibility- Driven Design Kenneth M. Anderson January 20, 2005

L23.1 Introduction... 2

The GoF Design Patterns Reference

Patterns. Giovanni Sakti. in Software Engineering. Starqle

Applying the Factory Method Design Pattern

The Object Recursion Pattern

Model-View-Controller Architecture

As a programmer, you know how easy it can be to get lost in the details

More on Design. CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

Summary of the course lectures

Object Design II: Design Patterns

Work groups meeting 3

CHAPTER 6: CREATIONAL DESIGN PATTERNS

Introduction to Design Patterns

CS/CE 2336 Computer Science II

3 Product Management Anti-Patterns by Thomas Schranz

Design Patterns

A Rapid Overview of UML

VOL. 4, NO. 12, December 2014 ISSN ARPN Journal of Science and Technology All rights reserved.

4.1 Introduction Programming preliminaries Constructors Destructors An example... 3

Slide 1. Design Patterns. Prof. Mirco Tribastone, Ph.D

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Extensibility Design Patterns From The Initial Stage of Application Life-Cycle

Software Engineering I (02161)

Patterns. Erich Gamma Richard Helm Ralph Johnson John Vlissides

Second Midterm Review

An Expert System for Design Patterns Recognition

Software Engineering I (02161)

Software Reengineering Refactoring To Patterns. Martin Pinzger Delft University of Technology

Design Patterns For Object Oriented Software Development Acm Press

Introduction to Design Patterns

Design Patterns. it s about the Observer pattern, the Command pattern, MVC, and some GUI. some more

Advanced Topics in Software Engineering (02265) Ekkart Kindler

Refining the Observer Pattern: The Middle Observer Pattern

CS112 Lecture: Reuse, Packages, Patterns

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Simulation Engines TDA571 DIT030 Architecture and design. Tommaso Piazza

CHAPTER 5 GENERAL OOP CONCEPTS

Transcription:

Cocoa Design Patterns Erik M. Buck October 17, 2009

Topics n What is a design pattern? n Why Focus on design patterns? n What is the Model View Controller design pattern? n Using MVC n When wouldn t you use MVC? n Pattern implementation example n Bonus patterns

What is a design pattern? n Practical solutions to recurring problems n Don't require amazing programming tricks n A vocabulary or shorthand to use when explaining complex software n Not specific algorithms or data structures

What is a design pattern? (continued) n At a minimum, design patterns contain four essential elements: The pattern name A brief description of the motivation for the pattern or the problem solved by the pattern A detailed description of the pattern and examples The consequences of using the pattern

What is a design pattern? (continued) n Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John M. Vlissides (1994) ISBN-10: 0201633612 ISBN-13: 978-0201633610 n Cocoa Design Patterns by Erik M. Buck and Donald Yacktman ISBN-10: 0321535022 ISBN-13: 978-0321535023

What is a design pattern? (continued) n Web: http://www.cocoadesignpatterns.com http:// en.wikipedia.org/wiki/ Design_pattern_(computer_science) http://developer.apple.com/iphone/library/ documentation/cocoa/conceptual/ CocoaFundamentals/CocoaDesignPatterns/ CocoaDesignPatterns.html http://c2.com/cgi/wiki?designpatternsbook http://www.asp.net/mvc/

Why focus on design patterns? n Maximize programmer productivity by reducing lifetime software development and maintenance costs n Object reuse is the answer n Design patterns identify successful strategies for achieving reuse on a large scale

Guiding principles of design n Solve a problem in a general reusable way n Ensure that the patterns are flexible and applicable in many contexts n The same strategies that apply to design of individual objects also apply to patterns n Patterns that involve many objects benefit even more from good object-oriented design than simpler systems

Guiding principles of design (continued) n Minimize Coupling Coupling refers to dependencies between objects Dependencies reduce opportunities for reusing the objects independently Coupling also applies to subsystems within large systems For example, the Model-View-Controller (MVC) pattern organizes subsystems of classes and is applied to the design of entire applications The primary intent of the MVC pattern is to partition a complex system of objects into three major subsystems and minimize coupling between the subsystems

Guiding principles of design (continued) n Design for change Designs that are too inflexible ultimately restrict opportunities for reuse In the worst case, no reuse occurs because it s easier to redesign and re-implement a system than it is to make changes within an existing rigid design It s possible to anticipate certain types of changes and accommodate them in a design

Guiding principles of design (continued) n Emphasize interfaces rather than implementations Interfaces provide a metaphorical contract between an object and the users of the object A contract is necessary for programmers to feel confident reusing framework objects

Guiding principles of design (continued) n Find the optimal granularity Design patterns operate at different levels of granularity MVC is applied to large subsystems of cooperating classes, but the Singleton pattern makes sure that only one instance of a class is ever created and provides access to that instance Certain problems are best solved by small patterns that involve only a few classes while other problems are solved by reusing grand overarching patterns

Guiding principles of design (continued) n Use composition in preference to inheritance It can t be said enough times that coupling is the enemy It is ironic that inheritance is simultaneously one of the most powerful tools in object oriented programming and one of the leading causes of coupling

What is MVC? n MVC is a pattern for designing applications that store information, retrieve information, present information to a user, and/or enable a user to edit or otherwise manipulate the information n MVC is one of the oldest and most successfully reused software design patterns n It s a high level pattern for organizing large groups of cooperating objects into distinct subsystems: the Model, the View, and the Controller

What is MVC? (continued) n Model Provides the unique capabilities and information storage for an application n View Enables user interaction with information gathered from the Model n Controller Decouples the Model from the Views

What is MVC? (continued) n The primary purpose of MVC is to decouple the Model subsystem from the Views so that each can change independently n The Controller subsystem provides that decoupling n The Controller subsystem is often tricky to design and may seem like it adds needless complexity

What is MVC? (continued) n The flow of information is between the Model and the Views, so why introduce another layer? The Controller subsystem provides insulation between the Model and the Views n Views tend to change much more often than Models n There potentially many Views n Change the Model without affecting all of the Views

What is MVC? (continued) It s usually easier to test a Model directly rather than through a user interface When testing through a user interface, extra effort is required to determine whether a test failure is the result of a bug in the Model or a bug in the View or both The Model is often developed by one team and the user interfaces are developed by another The skills needed to develop the Model may be very different than those needed to produce an excellent user experience

Using MVC n Editor or viewer applications Applications that are editors or viewers for underlying information are naturally organized with the MVC pattern When there are multiple ways to view the same information When there is a consistent way of viewing different types of information To simplify simultaneous development of Models and Views by teams

When wouldn t you use MVC? n Operating system device drivers The application used to configure device drivers might adopt the MVC design, but the drivers themselves must conform to operating system interfaces and don t usually present information directly to users n Long running computation intensive programs Long running calculations are often batch processed and again don t directly provide a user interface

Pattern implementation example MVC Game Games present information and enable user interaction Transparis Transparis 3D

One Model - Multiple Views Model Identical implementation in both games Model Controller View Controller View Controller Controller View Loose coupling View

Classes Transparis Transparis 3D

Multiple Models - One View Model Core Data Model Model Controller Model Controller View Controller Controller View

Classes Transparis 3D Transparis 3D Core Data

Core Data Model

Bonus Patterns n Category n Notification

Category: Add methods to existing classes

Category: Implementation locality Transparis Transparis 3D

Notification: Communicate without coupling Model Model Controller View Controller View Controller Controller View View