Pro Objective-C Design Patterns for ios

Similar documents
UNIT I Introduction to Design Patterns

UNIT I Introduction to Design Patterns

Introduction to Software Engineering: Object Design I Reuse & Patterns

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

SYLLABUS CHAPTER - 1 [SOFTWARE REUSE SUCCESS FACTORS] Reuse Driven Software Engineering is a Business

Object-oriented Software Design Patterns

Design Pattern. CMPSC 487 Lecture 10 Topics: Design Patterns: Elements of Reusable Object-Oriented Software (Gamma, et al.)

Pro JavaScript. Development. Coding, Capabilities, and Tooling. Den Odell. Apress"

SDC Design patterns GoF

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

design patterns FOR B.tech (jntu - hyderabad & kakinada) (IV/I - CSE AND IV/II - IT) CONTENTS 1.1 INTRODUCTION TO DESIGN PATTERNS TTERNS... TTERN?...

The Strategy Pattern Design Principle: Design Principle: Design Principle:

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

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

I, J. Key-value observing (KVO), Label component, 32 text property, 39

CSCI Object Oriented Design: Frameworks and Design Patterns George Blankenship. Frameworks and Design George Blankenship 1

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

COPYRIGHTED MATERIAL. Table of Contents. Foreword... xv. About This Book... xvii. About The Authors... xxiii. Guide To The Reader...

Design Patterns. An introduction

TDDB84. Lecture 2. fredag 6 september 13

Design Patterns: Structural and Behavioural

A Reconnaissance on Design Patterns

Object-Oriented Oriented Programming

Design Pattern and Software Architecture: IV. Design Pattern

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

INSTITUTE OF AERONAUTICAL ENGINEERING

UP Requirements. Software Design - Dr Eitan Hadar (c) Activities of greater emphasis in this book. UP Workflows. Business Modeling.

Software Design COSC 4353/6353 D R. R A J S I N G H

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

PATTERN-ORIENTED SOFTWARE ARCHITECTURE

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

C++ for System Developers with Design Pattern

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

Design Patterns. (and anti-patterns)

What is Design Patterns?

DESIGN PATTERN - INTERVIEW QUESTIONS

Design Patterns Reid Holmes

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

OODP Session 4. Web Page: Visiting Hours: Tuesday 17:00 to 19:00

Ownership in Design Patterns. Master's Thesis Final Presentation Stefan Nägeli

Design patterns. Jef De Smedt Beta VZW

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

SWEN425 DESIGN PATTERNS

Overview CS Kinds of Patterns. Design Pattern. Factory Pattern Rationale. Kinds of Factory Patterns

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

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

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

Lecture 4: Observer Pattern, Event Library and Componentization

Socket attaches to a Ratchet. 2) Bridge Decouple an abstraction from its implementation so that the two can vary independently.

1 Software Architecture

Composite Pattern. IV.4 Structural Pattern

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Lectures 24 and 25 Introduction to Architectural Styles and Design Patterns

Software Development Project. Kazi Masudul Alam

Tuesday, October 4. Announcements

Using Design Patterns in Java Application Development

A few important patterns and their connections

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Writing your own Java I/O Decorator p. 102 Tools for your Design Toolbox p. 105 Exercise Solutions p. 106 The Factory Pattern Baking with OO

Applying Design Patterns to SCA Implementations

Keywords: Abstract Factory, Singleton, Factory Method, Prototype, Builder, Composite, Flyweight, Decorator.

TDDB84: Lecture 6. Adapter, Bridge, Observer, Chain of Responsibility, Memento, Command. fredag 4 oktober 13

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Iterator Pattern George Blankenship

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

Object Oriented Paradigm

Review Software Engineering October, 7, Adrian Iftene

Brief Note on Design Pattern

Design Patterns. Comp2110 Software Design. Department of Computer Science Australian National University. Second Semester

Design Patterns Reid Holmes

CS 2720 Practical Software Development University of Lethbridge. Design Patterns

Information systems modelling UML and service description languages

COSC 3351 Software Design. Design Patterns Behavioral Patterns (I)

R07. IV B.Tech. II Semester Supplementary Examinations, July, 2011

Application Architectures, Design Patterns

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Template Method Pattern. George Blankenship

Object-Oriented Design

Lecture 20: Design Patterns II

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

Creational Design Patterns

The Design Patterns Matrix From Analysis to Implementation

CSE 219 COMPUTER SCIENCE III BEHAVIORAL DESIGN PATTERNS SLIDES COURTESY: RICHARD MCKENNA, STONY BROOK UNIVERSITY

What is Design Patterns?

3 Product Management Anti-Patterns by Thomas Schranz

A Rapid Overview of UML

administrivia today UML start design patterns Tuesday, September 28, 2010

Design Patterns. CSE870: Advanced Software Engineering (Design Patterns): Cheng

Design Patterns! Acknowledgements!

CSE870: Advanced Software Engineering (Cheng) 1

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Microsoft Visual C# Step by Step. John Sharp

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

DESIGN PATTERNS SURESH BABU M ASST PROFESSOR VJIT

CSC207H: Software Design Lecture 6

CS/CE 2336 Computer Science II

Lecture 17: Patterns Potpourri. Copyright W. Howden 1

What is Design Patterns?

RELEVANCE OF DESIGN PATTERNS TODAY

Topics. Software Process. Agile. Requirements. Basic Design. Modular Design. Design Patterns. Testing. Quality. Refactoring.

Transcription:

Pro Objective-C Design Patterns for ios Carlo Chung

Contents Contents at a Glance About the Author About the Technical Reviewer Acknowledgments Preface x xi xii xiii Part I: Getting Your Feet Wet 1 Chapter 1: Hello, Design Patterns! 3 What This Book Is 3 What You Need Before You Can Begin 4 What You Need to Know Before You Can Begin 4 Design Deja-vu 5 The Origin of Design Patterns Model, View, and Controller (MVC) 6 - Encapsulating Data and Basic Behaviors In Model Objects 6 Presenting Information to the User with View Objects 7 Tying up the Model to the View with Controller Objects 7 MVC as a Compound Design Pattern 7 Issues That Can AffectYour Design 9 Programming To An Interface, Not An Implementation 9 protocol vs. Abstract Base Class (ABC) 10 Object Composition vs. Class Inheritance 11 Objects and Classes Used in this Book 13 Class Diagram 13 Object Diagram 17 How the Patterns are Organized 18 Summary 18 Chapter 2: A Case Study: Designing an App 19 Conceptualizing the Ideas 20 Designing the Look-and-Feel 21 Architectural Design 23 View Management 24 V

a CONTENTS Scribble Representation 27 Representation of a Saved Scribble 33 User Operations Reviewing the Patterns Used 44 Summary 44 Part II: Object Creation 45 Chapter 3: Prototype 47 What Is the Prototype Pattern? 48 When Would You Use the Prototype Pattern? 48 Shallow Copying vs. Deep Copying 49 Using Object Copying in the Cocoa Touch Framework 51 Implementing the Copy Method for the Mark Aggregate 52 Using a Cloned Mark As a "Pattern Template" 60 Summary 62 Chapter 4: Factory Method 63 What Is the Factory Method Pattern? 63 When Would You Use the Factory Method? 64 Why Is It a Safe Approach to Creating Objects? 65 Generating Different Canvases in TouchPainter 65 Using Canvases 70 Using Factory Methods Within the Cocoa Touch Framework 71 Summary 72 Chapter 5: Abstract Factory 73 Applying the Abstract Factory to the TouchPainter App 75 Using the Abstract Factory Within the Cocoa Touch Framework 81 Summary 84 Chapter 6: Builder 85 What Is the Builder Pattern? 85 When Would You Use the Builder Pattern? 87 Building Characters in a Chasing Game 88 Summary 96 Chapter 7: Singleton 97 What Is the Singleton Pattern? 97 When Would You Use the Singleton Pattern? 98 Implementing a Singleton in Objective-C 99 Subclassing a Singleton 103 Thread Safety 103 Using Singletons in the Cocoa Touch Framework 104 Using the UlApplication Class 104 Using the UlAccelerometer Class 104 Using the NSFileManager Class 104 Summary 105 Part III: Interface Adaptation 107 Chapter 8: Adapter 109 What Is the Adapter Pattern? 109 When Would You Use the Adapter Pattern? 112 37 Vi

CONTENTS So You Know Delegation 112 Implementing the Adapter Pattern with Objective-C Protocol 113 Designing and Implementing a Stroke Color Changing Mechanism 114 Implementing the Adapter Pattern with Objective-C Blocks in ios 4 119 Declaring a Block Reference 120 Creating a Block 120 Using a Block As an Adapter 121 Summary 125 Chapter 9: Bridge 127 What Is the Bridge Pattern? 127 When Would You Use the Bridge Pattern? 129 Creating a Virtual Emulator for ios 129 Summary 135 Chapter 10: Fagade 137 What Is the Fagade Pattern? 137 When Would You Use the Fagade Pattern? 138 Providing a Simplified Interface to a Set of Interfaces in the Subsystem 139 Using the Fagade Pattern in the TouchPainter App 142 Summary 144 Part IV: Decoupling of Objects 145 Chapter 11: Mediator 147 What Is the Mediator Pattern? 148 When Would You Use the Mediator Pattern? 149 Managing View Transition in the TouchPainter App 149 The Troubles of Modifying the Transition Logic 152 Centralizing the Flow of the Ul Traffic 154 Using the CoordinatingController in the Interface Builder 159 Summary 163 Chapter 12: Observer 165 What Is the Observer Pattern? 165 When Would You Use the Observer Pattern? 167 Using the Observer Pattern in Model-View-Controller 168 Using the Observer Pattern in the Cocoa Touch Framework 168 Notifications 168 Key-Value Observing 170 Updating Strokes on the CanvasView in TouchPainter 171 Summary 181 Part V: Abstract Collection 183 Chapter 13: Composite 185 What Is the Composite Pattern? 185 When Would You Use the Composite Pattern? 188 Understanding the Use of Mark in TouchPainter 188 Using Composites in the Cocoa Touch Framework 197 Summary 199 Chapter 14: Iterator 201 What Is the Iterator Pattern? 202 Vll

CONTENTS When Would You Use the Iterator Pattern? 204 Using Iterators in the Cocoa Touch Framework 204 NSEnumerator 205 Block-Based Enumeration 205 Fast Enumeration 206 Internal Enumeration 207 Enumerating Vertices of a Scribble 208 Enumerating Vertices of a Scribble (Internally) 214 Summary 216 Part VI: Behavioral Extension 219 Chapter 15: Visitor 221 What is the Visitor Pattern? 221 When Would You Use the Visitor Pattern 224 Rendering Marks in TouchPainter with Visitors 224 What Else Can A Visitor Do? 231 Can't I Just Use Categories Instead? 231 Summary 232 Chapter 16: Decorator 233 What Is the Decorator Pattern? 233 When Would You Use the Decorator Pattern? 235 Changing the "Skin" vs. "Guts" of an Object 235 Creating Image Filters for Ullmage 236 Implementing Decorators with True Subclasses 237 Implementing Decorators with Categories 246 Summary 252 Chapter 17: Chain of Responsibility 253 What Is the Chain of Responsibility Pattern? 254 When Would You Use the Chain of Responsibility Pattern? 255 Using the Chain of Responsibility Pattern in an RPG 255 Summary 262 Part Vli: Algorithm Encapsulation 263 Chapter 18: Template Method 265 What Is the Template Method Pattern? 265 When Would You Use the Template Method? 266 Using the Template Method to Make a Sandwich 267 Ensuring That the Template Method Is Working 273 Adding an Extra Step to the Template Method 275 Using the Template Method in the Cocoa Touch Framework 278 Custom Drawing in the UlView Class 278 Other Template Method Implementations in Cocoa Touch 279 Summary 279 Chapter 19: Strategy 281 What Is the Strategy Pattern? 281 When Would You Use the Strategy Pattern? 283 Applying Validation Strategies in UlTextField 283 Summary 291 viii

CONTENTS Chapter 20: Command 293 What Is the Command Pattern? 293 When Would You Use the Command Pattern? 294 Using the Command Pattern in the Cocoa Touch Framework 295 NSInvocation Objects 295 NSUndoManager 296 Implementing Undo/Redo in TouchPainter 297 Implementing Drawing/Undrawing with NSUndoManager 298 Home-Brewing Your Own Drawing/Undrawing Infrastructure 303 Allowing the User to Activate Undo/Redo 311 What Else Can a Command Do? 312 Summary 312 Part VIII: Performance and Object Access 313 Chapter 21: Flyweight 315 What Is the Flyweight Pattern? 315 When Would You Use the Flyweight Pattern? 317 Creating a Hundred-Flower Pool 318 Designing and Implementing Sharable Flowers 319 Summary 326 Chapter 22: Proxy 327 What Is the Proxy Pattern? 328 When Would You Use the Proxy Pattern? 329 Lazy-Loading an Image with a Virtual Proxy 329 Designing and Implementing a Scribble Thumbnail View 331 Using a Proxy Pattern in the Cocoa Touch Framework 336 Summary 338 Part IX: State Of Object 339 Chapter 23: Memento 341 What's the Memento Pattern? 341 When Would You Use the Memento Pattern? 343 Using the Memento Pattern in TouchPainter 343 Saving a Scribble 344 Restoring a Scribble 34*> Designing and Implementing ScribbleMemento 347 The Memento Pattern in the Cocoa Touch Framework 357 Summary 359 Index 361 Ix