E-Book, Englisch, 568 Seiten, eBook
Freeman Pro Design Patterns in Swift
1. Auflage 2015
ISBN: 978-1-4842-0394-1
Verlag: APRESS
Format: PDF
Kopierschutz: 1 - PDF Watermark
E-Book, Englisch, 568 Seiten, eBook
ISBN: 978-1-4842-0394-1
Verlag: APRESS
Format: PDF
Kopierschutz: 1 - PDF Watermark
Zielgruppe
Popular/general
Autoren/Hrsg.
Weitere Infos & Material
1;Contents at a Glance;3
2;Contents;550
3;About the Author;567
4;About the Technical Reviewer;568
5;Part I: Getting Ready;5
5.1;Chapter 1: Understanding Design Patterns;6
5.1.1;Putting Design Patterns into Context;6
5.1.1.1;Introducing Design Patterns;7
5.1.1.2;Understanding the Structure of a Design Pattern;7
5.1.1.3;Quantifying the Value of Design Patterns;8
5.1.1.4;Using a Design Pattern After the Problem Occurred;9
5.1.1.5;Understanding the Limitations of Design Patterns;9
5.1.2;About This Book;10
5.1.2.1;What Do You Need to Know?;10
5.1.2.2;What Software Do You Need?;10
5.1.2.3;What Is the Structure of This Book?;10
5.1.2.4;Where Can You Get the Example Code?;11
5.1.3;Summary;11
5.2;Chapter 2: Getting Used to Xcode;12
5.2.1;Working with Xcode Playgrounds;12
5.2.1.1;Creating a Playground;13
5.2.1.2;Displaying the Value History of a Variable;15
5.2.1.3;Using the Value Timeline;18
5.2.1.4;Displaying UI Components in a Playground;19
5.2.2;Working with OS X Command Line Tool Projects;21
5.2.2.1;Creating a Command-Line Project;21
5.2.2.2;Understanding the Xcode Layout;23
5.2.2.3;Adding a New Swift File;24
5.2.3;Summary;27
5.3;Chapter 3: Creating the SportsStore App;28
5.3.1;Creating an Unstructured iOS App Project;28
5.3.1.1;Creating the Project;30
5.3.1.2;Understanding the Xcode Layout;31
5.3.1.3;Defining the Data;31
5.3.2;Creating the Basic Layout;34
5.3.2.1;Adding the Basic Components;35
5.3.2.2;Configuring Auto Layout;37
5.3.2.3;Testing the Basic Layout;38
5.3.3;Implementing the Total Label;39
5.3.3.1;Creating the Reference;39
5.3.3.2;Updating the Display;41
5.3.4;Implementing the Table Cells;42
5.3.4.1;Defining the Custom Table Cell and Layout;43
5.3.4.2;Setting the Table Cell Layout Constraints;45
5.3.4.3;Creating the Table Cell Class and Outlets;45
5.3.4.4;Implementing the Data Source Protocol;47
5.3.4.5;Registering the Data Source;49
5.3.4.6;Testing the Data Source;49
5.3.5;Handling the Editing Actions;50
5.3.5.1;Handling the Events;51
5.3.6;Testing the SportsStore App;53
5.3.7;Summary;54
6;Part II: The Creation Patterns;55
6.1;Chapter 4: The Object Template Pattern;56
6.1.1;Preparing the Example Project;57
6.1.2;Understanding the Problem Addressed by the Pattern;57
6.1.3;Understanding the Object Template Pattern;60
6.1.4;Implementing the Object Template Pattern;61
6.1.5;Understanding the Benefits of the Pattern;62
6.1.5.1;The Benefit of Decoupling;62
6.1.5.2;The Benefit of Encapsulation;63
6.1.5.3;The Benefit of an Evolving Public Presentation;66
6.1.6;Understanding the Pitfalls of the Pattern;68
6.1.7;Examples of the Object Template Pattern in Cocoa;68
6.1.8;Applying the Pattern to the SportsStore App;68
6.1.8.1;Preparing the Example Application;69
6.1.8.2;Creating the Product Class;71
6.1.8.3;Applying the Product Class;73
6.1.8.3.1;Ensuring View and Model Separation;75
6.1.8.4;Expanding the Summary Display;76
6.1.9;Summary;77
6.2;Chapter 5: The Prototype Pattern;78
6.2.1;Understanding the Problem Addressed by the Pattern;79
6.2.1.1;Incurring Expensive Initializations;79
6.2.1.2;Creating Template Dependencies;80
6.2.2;Understanding the Prototype Pattern;82
6.2.3;Implementing the Prototype Pattern;82
6.2.3.1;Cloning Reference Types;85
6.2.3.1.1;Implementing the NSCopying Protocol;86
6.2.3.2;Understanding Shallow and Deep Copying;88
6.2.3.2.1;Implementing Deep Copying;90
6.2.3.3;Copying Arrays;92
6.2.4;Understanding the Benefits of the Prototype Pattern;94
6.2.4.1;Avoiding Expensive Initializations;94
6.2.4.2;Separating Object Creation from Object Use;97
6.2.4.2.1;(Not Really) Solving the Problem;98
6.2.4.2.2;Revealing the Underlying Problem;99
6.2.4.2.3;(Not Really) Solving the Underlying Problem;101
6.2.4.2.4;Applying the Prototype Pattern;101
6.2.5;Understanding the Pitfalls of the Prototype Pattern;103
6.2.5.1;Understanding the Deep vs. Shallow Pitfall;103
6.2.5.2;Understanding the Exposure Distortion Pitfall;104
6.2.5.3;Understanding the Nonstandard Protocol Pitfall;104
6.2.6;Examples of the Prototype Pattern in Cocoa;104
6.2.6.1;Using Cocoa Arrays;104
6.2.6.1.1;Shallow Copying a Cocoa Array;106
6.2.6.1.2;Creating a Deep Copy of a Cocoa Array;106
6.2.6.2;Using the NSCopying Property Attribute;107
6.2.7;Applying the Pattern to the SportsStore App;108
6.2.7.1;Preparing the Example Application;109
6.2.7.2;Implementing NSCopying in the Product Class;109
6.2.7.3;Creating the Logger Class;110
6.2.7.4;Logging Changes in the View Controller;111
6.2.7.5;Testing the Changes;113
6.2.8;Summary;113
6.3;Chapter 6: The Singleton Pattern;114
6.3.1;Preparing the Example Project;115
6.3.2;Understanding the Problem That the Pattern Solves;115
6.3.2.1;Understanding the Shared Resource Encapsulation Problem;116
6.3.3;Understanding the Singleton Pattern;118
6.3.4;Implementing the Singleton Pattern;119
6.3.4.1;The Quick Singleton Implementation;119
6.3.4.2;Creating a Conventional Singleton Implementation;122
6.3.4.3;Dealing with Concurrency;123
6.3.4.3.1;Serializing Access;126
6.3.5;Understanding the Pitfalls of the Singleton Pattern;129
6.3.5.1;Understanding the Leakage Pitfall;129
6.3.5.2;Understanding the Shared Code File Pitfall;130
6.3.5.3;Understanding the Concurrency Pitfalls;130
6.3.5.3.1;Not Applying Concurrency Protections;130
6.3.5.3.2;Applying Concurrency Protections Consistently;130
6.3.5.3.3;Bad Optimization;130
6.3.6;Examples of the Singleton Pattern in Cocoa;131
6.3.7;Applying the Pattern to the SportsStore Application;131
6.3.7.1;Protecting the Data Array;132
6.3.7.2;Protecting the Callback;133
6.3.7.3;Defining the Singleton;134
6.3.8;Summary;137
6.4;Chapter 7: The Object Pool Pattern;138
6.4.1;Preparing the Example Project;139
6.4.2;Understanding the Problem That the Pattern Solves;139
6.4.3;Understanding the Object Pool Pattern;140
6.4.4;Implementing the Object Pool Pattern;142
6.4.4.1;Defining the Pool Class;142
6.4.4.1.1;Protecting the Data Array;143
6.4.4.1.2;Ensuring Objects Are Available to Be Checked Out;144
6.4.4.2;Consuming the Pool Class;146
6.4.5;Understanding the Pitfalls of the Object Pool Pattern;149
6.4.6;Examples of the Object Pool Pattern in Cocoa;149
6.4.7;Applying the Pattern to the SportsStore Application;150
6.4.7.1;Preparing the Example Application;151
6.4.7.2;Creating the (Fake) Server;151
6.4.7.3;Creating the Object Pool;151
6.4.7.4;Applying the Object Pool;153
6.4.8;Summary;156
6.5;Chapter 8: Object Pool Variations;157
6.5.1;Preparing the Example Project;158
6.5.2;Understanding the Object Pool Pattern Variations;158
6.5.2.1;Understanding the Object Creation Strategy;158
6.5.2.2;Understanding the Object Reuse Strategy;163
6.5.2.2.1;Applying the Protocol;165
6.5.2.2.2;Testing the Strategy;166
6.5.2.3;Understanding the Empty Pool Strategy;167
6.5.2.3.1;Implementing the Failing Request Strategy;168
6.5.2.3.2;Dealing with Exhausted Pools;172
6.5.2.3.3;Creating an Elastic Pool;175
6.5.2.4;Understanding the Allocation Strategy;179
6.5.3;Understanding the Pitfalls of the Pattern Variations;182
6.5.3.1;Understanding the Expectation Gap Pitfall;182
6.5.3.2;Understanding the Over- and Under-utilization Pitfalls;183
6.5.4;Examples of the Pattern Variations in Cocoa;183
6.5.5;Applying a Pattern Variation to SportsStore;183
6.5.6;Summary;185
6.6;Chapter 9: The Factory Method Pattern;186
6.6.1;Preparing the Example Project;187
6.6.2;Understanding the Problem That the Pattern Solves;188
6.6.3;Understanding the Factory Method Pattern;190
6.6.4;Implementing the Factory Method Pattern;191
6.6.4.1;Defining a Global Factory Method;192
6.6.4.2;Using a Base Class;193
6.6.4.2.1;Delegating Decisions for Deeper Class Hierarchies;195
6.6.5;Variations on the Factory Method Pattern;198
6.6.6;Understanding the Pitfalls of the Pattern;200
6.6.7;Examples of the Factory Method Pattern in Cocoa;200
6.6.8;Applying the Pattern to the SportsStore Application;201
6.6.8.1;Preparing the Example Application;201
6.6.8.2;Implementing the Factory Method Pattern;203
6.6.8.3;Consuming the Factory Method Pattern;204
6.6.9;Summary;205
6.7;Chapter 10: Abstract Factory Pattern;206
6.7.1;Preparing the Example Project;207
6.7.2;Understanding the Problem That the Pattern Solves;210
6.7.3;Understanding the Abstract Factory Pattern;211
6.7.4;Implementing the Abstract Factory Pattern;212
6.7.4.1;Creating the Abstract Factory;213
6.7.4.2;Creating the Concrete Factories;213
6.7.4.3;Completing the Abstract Factory;214
6.7.4.4;Consuming the Abstract Factory Pattern;215
6.7.5;Variations on the Abstract Factory Pattern;216
6.7.5.1;Hiding the Abstract Factory Class;216
6.7.5.2;Applying the Singleton Pattern to the Concrete Factories;218
6.7.5.3;Applying the Prototype Pattern to the Implementation Classes;219
6.7.5.3.1;Preparing the Example Application;220
6.7.5.3.2;Applying the Prototype Pattern;223
6.7.6;Understanding the Pitfalls of the Pattern;226
6.7.7;Examples of the Pattern in Cocoa;226
6.7.8;Applying the Pattern to the SportsStore Application;226
6.7.8.1;Preparing the Example Application;226
6.7.8.2;Defining the Implementation Protocols and Classes;227
6.7.8.3;Defining the Abstract and Concrete Factory Classes;228
6.7.8.4;Consuming the Factories and Implementation Classes;229
6.7.9;Summary;230
6.8;Chapter 11: The Builder Pattern;231
6.8.1;Preparing the Example Project;232
6.8.1.1;Understanding the Problems That the Pattern Solves;233
6.8.2;Understanding the Builder Pattern;236
6.8.3;Implementing the Builder Pattern;237
6.8.3.1;Defining the Builder Class;237
6.8.3.2;Consuming the Builder;238
6.8.3.3;Understanding the Impact of the Pattern;239
6.8.3.3.1;Changing the Process;240
6.8.3.3.2;Changing the Object;240
6.8.3.3.3;Avoiding Inconsistent Configurations;242
6.8.4;Variations on the Builder Pattern;243
6.8.5;Understanding the Pitfalls of the Builder Pattern;245
6.8.6;Examples of the Builder Pattern in Cocoa;245
6.8.7;Applying the Pattern to the SportsStore Application;246
6.8.7.1;Preparing the Example Application;246
6.8.7.2;Defining the Builder Class;247
6.8.7.3;Using the Builder Class;248
6.8.8;Summary;248
7;Part III: The Structural Patterns;249
7.1;Chapter 12: The Adapter Pattern;250
7.1.1;Preparing the Example Project;251
7.1.1.1;Creating the Data Sources;251
7.1.1.2;Defining the Application;252
7.1.2;Understanding the Problem That the Pattern Solves;254
7.1.3;Understanding the Adapter Pattern;255
7.1.4;Implementing the Adapter Pattern;256
7.1.5;Variations on the Adapter Pattern;258
7.1.5.1;Defining an Adapter as a Wrapper Class;259
7.1.5.2;Creating a Two-Way Adapter;260
7.1.6;Understanding the Pitfalls of the Adapter Pattern;263
7.1.7;Examples of the Adapter Pattern in Cocoa;263
7.1.8;Applying the Pattern to the SportsStore Application;264
7.1.8.1;Preparing the Example Application;264
7.1.8.2;Defining the Adapter Class;264
7.1.8.3;Using the Adapted Functionality;266
7.1.9;Summary;267
7.2;Chapter 13: The Bridge Pattern;268
7.2.1;Preparing the Example Project;269
7.2.2;Understanding the Problem That the Pattern Solves;271
7.2.3;Understanding the Bridge Pattern;272
7.2.4;Implementing the Bridge Pattern;274
7.2.4.1;Dealing with the Messages;274
7.2.4.2;Dealing with the Channels;275
7.2.4.3;Creating the Bridge;276
7.2.4.4;Adding a New Message Type and Channel;277
7.2.5;Variations on the Bridge Pattern;281
7.2.5.1;Collapsing the Bridge;283
7.2.6;Understanding the Pitfalls of the Bridge Pattern;285
7.2.7;Examples of the Bridge Pattern in Cocoa;285
7.2.8;Applying the Pattern to the SportsStore Application;285
7.2.8.1;Preparing the Example Application;285
7.2.8.2;Understanding the Problem;286
7.2.8.3;Defining the Bridge Class;286
7.2.9;Summary;288
7.3;Chapter 14: The Decorator Pattern;289
7.3.1;Preparing the Example Project;290
7.3.2;Understanding the Problem That the Pattern Solves;291
7.3.3;Understanding the Decorator Pattern;294
7.3.4;Implementing the Decorator Pattern;294
7.3.5;Variations on the Decorator Pattern;296
7.3.5.1;Creating Decorators with New Functionality;296
7.3.5.1.1;Using the New Functionality;298
7.3.5.1.2;Understanding the Limitations of Decorators with New Functionality;299
7.3.5.2;Creating Consolidated Decorators;300
7.3.6;Understanding the Pitfalls of the Decorator Pattern;302
7.3.6.1;The Side-Effect Pitfall;302
7.3.7;Examples of the Decorator Pattern in Cocoa;303
7.3.8;Applying the Pattern to the SportsStore Application;303
7.3.8.1;Preparing the Example Application;303
7.3.8.2;Creating the Decorators;303
7.3.8.3;Applying the Decorators;304
7.3.9;Summary;305
7.4;Chapter 15: The Composite Pattern;306
7.4.1;Preparing the Example Project;307
7.4.2;Understanding the Problem That the Pattern Solves;309
7.4.3;Understanding the Composite Pattern;309
7.4.4;Implementing the Composite Pattern;310
7.4.4.1;Applying the Pattern;311
7.4.5;Understanding the Pitfalls of the Composite Pattern;313
7.4.6;Examples of the Composite Pattern in Cocoa;315
7.4.7;Applying the Pattern to the SportsStore Application;315
7.4.7.1;Preparing the Example Application;315
7.4.7.2;Defining the Composite Class;316
7.4.7.3;Applying the Pattern;317
7.4.8;Summary;318
7.5;Chapter 16: The Façade Pattern;319
7.5.1;Preparing the Example Project;320
7.5.2;Understanding the Problem That the Pattern Solves;322
7.5.3;Understanding the Façade Pattern;323
7.5.4;Implementing the Façade Pattern;324
7.5.4.1;Applying the Façade;325
7.5.5;Variations on the Façade Pattern;326
7.5.6;Understanding the Pitfalls of the Façade Pattern;327
7.5.7;Examples of the Façade Pattern in Cocoa;327
7.5.8;Applying the Pattern to the SportsStore Application;329
7.5.8.1;Preparing the Example Application;330
7.5.8.2;Creating the Façade Class;330
7.5.8.3;Applying the Façade Class;331
7.5.9;Summary;332
7.6;Chapter 17: The Flyweight Pattern;333
7.6.1;Preparing the Example Project;334
7.6.2;Understanding the Problems That the Pattern Solves;335
7.6.3;Understanding the Flyweight Pattern;336
7.6.4;Implementing the Flyweight Pattern;337
7.6.4.1;Creating the Flyweight Protocol;337
7.6.4.2;Creating the Flyweight Implementation Class;338
7.6.4.3;Adding Concurrency Protections;339
7.6.4.4;Creating the Flyweight Factory Class;341
7.6.4.5;Applying the Flyweight;342
7.6.5;Variations on the Flyweight Pattern;344
7.6.6;Understanding the Pitfalls of the Flyweight Pattern;346
7.6.6.1;Understanding the Extrinsic Duplication Pitfall;346
7.6.6.2;Understanding the Mutable Extrinsic Data Pitfall;346
7.6.6.3;Understanding the Concurrent Access Pitfall;346
7.6.6.4;Understanding the Over-optimization Pitfall;346
7.6.6.5;Understanding the Misapplication Pitfall;347
7.6.7;Examples of the Flyweight Pattern in Cocoa;347
7.6.8;Applying the Pattern to the SportsStore Application;348
7.6.8.1;Preparing the Example Application;348
7.6.8.2;Creating the Flyweight Protocol and Implementation Class;348
7.6.8.3;Creating the Flyweight Factory;349
7.6.8.4;Applying the Flyweight;350
7.6.9;Summary;350
7.7;Chapter 18: The Proxy Pattern;351
7.7.1;Preparing the Example Project;352
7.7.2;Understanding the Problems That the Pattern Solves;353
7.7.2.1;Understanding the Remote Object Problem;353
7.7.2.2;Understanding the Expensive Operation Problem;353
7.7.2.3;Understanding the Restricted Access Problem;353
7.7.3;Understanding the Proxy Pattern;353
7.7.3.1;Solving the Remote Object Problem;354
7.7.3.2;Solving the Expensive Operation Problem;355
7.7.3.3;Solving the Restricted Access Problem;355
7.7.4;Implementing the Proxy Pattern;356
7.7.4.1;Implementing the Remote Object Proxy;356
7.7.4.1.1;Defining the Proxy Protocol;356
7.7.4.1.2;Defining the Proxy Implementation Class;357
7.7.4.1.3;Using the Remote Object Proxy;358
7.7.4.2;Implementing the Expensive Operation Proxy;358
7.7.4.2.1;Deferring the Operation;360
7.7.4.3;Implementing the Access Restriction Proxy;362
7.7.4.3.1;Creating the Authorization Source;362
7.7.4.3.2;Creating the Proxy Object;363
7.7.4.3.3;Applying the Proxy;364
7.7.5;Variations on the Proxy Pattern;364
7.7.5.1;Implementing a Reference Counting Proxy;367
7.7.6;Understanding the Pitfalls of the Proxy Pattern;369
7.7.7;Examples of the Proxy Pattern in Cocoa;369
7.7.8;Applying the Pattern to the SportsStore Application;369
7.7.8.1;Preparing the Example Application;370
7.7.8.2;Defining the Protocol, Factory Method, and Proxy Class;370
7.7.8.3;Updating the Product Data Store;371
7.7.8.4;Sending Stock Level Updates;372
7.7.9;Summary;374
8;Part IV: The Behavioral Patterns;375
8.1;Chapter 19: The Chain of Responsibility Pattern;376
8.1.1;Preparing the Example Project;377
8.1.2;Understanding the Problem That the Pattern Solves;379
8.1.3;Understanding the Chain of Responsibility Pattern;380
8.1.4;Implementing the Chain of Responsibility Pattern;381
8.1.4.1;Creating and Providing the Chain of Responsibility;382
8.1.4.2;Applying the Chain of Responsibility Pattern;383
8.1.5;Variations on the Chain of Responsibility Pattern;384
8.1.5.1;Applying the Factory Method Pattern;384
8.1.5.2;Indicating Whether Responsibility Was Taken for the Request;385
8.1.5.3;Notifying All Links in the Chain;387
8.1.6;Understanding the Pitfalls of the Pattern;389
8.1.7;Examples of the Pattern in Cocoa;389
8.1.8;Applying the Pattern to the SportsStore Application;390
8.1.8.1;Preparing the Example Application;390
8.1.8.2;Defining the Chain and its Links;390
8.1.9;Summary;392
8.2;Chapter 20: The Command Pattern;393
8.2.1;Preparing the Example Project;394
8.2.2;Understanding the Problem That the Pattern Solves;395
8.2.3;Understanding the Command Pattern;396
8.2.4;Implementing the Command Pattern;397
8.2.4.1;Defining the Command Protocol;397
8.2.4.2;Defining the Command Implementation Class;397
8.2.4.3;Applying the Command Pattern;398
8.2.4.4;Applying Concurrent Protections;400
8.2.4.5;Using the Undo Feature;402
8.2.5;Variations on the Command Pattern;403
8.2.5.1;Creating Composite Commands;403
8.2.5.2;Using Commands as Macros;405
8.2.5.3;Using Closures as Commands;407
8.2.6;Understanding the Pitfalls of the Command Pattern;410
8.2.7;Examples of the Command Pattern in Cocoa;410
8.2.8;Applying the Pattern to the SportsStore Application;410
8.2.8.1;Preparing the Example Application;410
8.2.8.2;Implementing the Undo Feature;411
8.2.8.2.1;Triggering an Undo Command;413
8.2.9;Summary;413
8.3;Chapter 21: The Mediator Pattern;414
8.3.1;Preparing the Example Project;415
8.3.2;Understanding the Problem That the Pattern Solves;417
8.3.3;Understanding the Mediator Pattern;419
8.3.4;Implementing the Mediator Pattern;420
8.3.4.1;Defining the Meditator Class;420
8.3.4.2;Conforming to the Peer Protocol;421
8.3.4.3;Implementing Concurrency Protections;423
8.3.4.3.1;Implementing Concurrency Protections in the Mediator;423
8.3.4.3.2;Implementing Concurrency Protections in the Peer;424
8.3.5;Variations on the Mediator Pattern;426
8.3.5.1;Putting More Logic Into the Mediator;426
8.3.5.2;Generalizing the Mediator-Peer Relationship;427
8.3.5.2.1;Generalizing the Mediator with the Command Pattern;427
8.3.5.2.2;Generalizing the Mediator with Messages;431
8.3.6;Understanding the Pitfalls of the Mediator Pattern;434
8.3.6.1;The Single Protocol Pitfall;435
8.3.7;Examples of the Mediator Pattern in Cocoa;435
8.3.8;Applying the Pattern to the SportsStore Application;437
8.3.9;Summary;437
8.4;Chapter 22: The Observer Pattern;438
8.4.1;Preparing the Example Project;439
8.4.2;Understanding the Problem That the Pattern Solves;440
8.4.3;Understanding the Observer Pattern;441
8.4.4;Implementing the Observer Pattern;442
8.4.4.1;Creating the Base Subject Class;443
8.4.4.2;Conforming to the Subject Protocol;444
8.4.4.3;Conforming to the Observer Protocol;445
8.4.4.4;Consuming the Pattern;446
8.4.5;Variations on the Observer Pattern;446
8.4.5.1;Generalizing Notifications;447
8.4.5.1.1;Understanding the Notification Object Pitfall;450
8.4.5.2;Using Weak References;452
8.4.5.3;Dealing with Short-Lived Subjects;454
8.4.6;Understanding the Pitfalls of the Observer Pattern;457
8.4.7;Examples of the Observer Pattern in Cocoa;457
8.4.7.1;User Interface Events;457
8.4.7.2;Observing Property Changes;458
8.4.8;Applying the Pattern to the SportsStore Application;459
8.4.8.1;Preparing the Example Application;459
8.4.8.2;Applying the Pattern;460
8.4.9;Summary;462
8.5;Chapter 23: The Memento Pattern;463
8.5.1;Preparing the Example Project;464
8.5.2;Understanding the Problem That the Pattern Solves;466
8.5.3;Understanding the Memento Pattern;466
8.5.4;Implementing the Memento Pattern;468
8.5.4.1;Implementing the Memento Class;468
8.5.4.2;Using the Memento;470
8.5.5;Variations on the Memento Pattern;471
8.5.6;Understanding the Pitfalls of the Memento Pattern;473
8.5.7;Examples of the Memento Pattern in Cocoa;474
8.5.8;Applying the Pattern to the SportsStore Application;477
8.5.8.1;Preparing the Example Application;478
8.5.8.2;Implementing the Pattern;478
8.5.9;Summary;480
8.6;Chapter 24: The Strategy Pattern;481
8.6.1;Preparing the Example Project;482
8.6.2;Understanding the Problem That the Pattern Solves;482
8.6.3;Understanding the Strategy Pattern;484
8.6.4;Implementing the Strategy Pattern;485
8.6.4.1;Defining the Strategies and the Context Class;485
8.6.4.2;Consuming the Pattern;486
8.6.5;Variations on the Strategy Pattern;487
8.6.6;Understanding the Pitfalls of the Strategy Pattern;488
8.6.7;Examples of the Strategy Pattern in Cocoa;488
8.6.7.1;Cocoa Protocol-Based Strategies;488
8.6.7.2;Cocoa Selector-Based Strategies;490
8.6.8;Applying the Pattern to the SportsStore Application;491
8.6.9;Summary;491
8.7;Chapter 25: The Visitor Pattern;492
8.7.1;Preparing the Example Project;493
8.7.2;Understanding the Problem That the Pattern Solves;494
8.7.3;Understanding the Visitor Pattern;496
8.7.4;Implementing the Visitor Pattern;497
8.7.4.1;Conforming to the Shape Protocol;500
8.7.4.2;Creating the Visitors;502
8.7.4.3;Applying the Visitors;503
8.7.5;Variations on the Visitor Pattern;503
8.7.6;Understanding the Pitfalls of the Visitor Pattern;503
8.7.7;Examples of the Visitor Pattern in Cocoa;504
8.7.8;Applying the Pattern to the SportsStore Application;504
8.7.9;Summary;504
8.8;Chapter 26: The Template Method Pattern;505
8.8.1;Preparing the Example Project;506
8.8.2;Understanding the Problem That the Pattern Solves;507
8.8.3;Understanding the Template Method Pattern;508
8.8.4;Implementing the Template Method Pattern;508
8.8.5;Variations on the Template Method Pattern;510
8.8.6;Understanding the Pitfalls of the Pattern;512
8.8.7;Examples of the Template Method Pattern in Cocoa;512
8.8.8;Applying the Pattern to the SportsStore Application;512
8.8.9;Summary;512
9;Part V: The MVC Pattern;513
9.1;Chapter 27: The Model/View/Controller Pattern;514
9.1.1;Preparing the Example Project;515
9.1.2;Understanding the Problem That the Pattern Solves;515
9.1.3;Understanding the MVC Pattern;515
9.1.3.1;Understanding the MVC Application Sections;517
9.1.3.1.1;Understanding the Model;518
9.1.3.1.2;Understanding Controllers;519
9.1.3.1.3;Understanding Views;519
9.1.3.1.4;Understanding Cross-Cutting Concerns;520
9.1.4;Implementing the MVC Pattern;520
9.1.4.1;Defining the Common Code;521
9.1.4.2;Defining the Framework;522
9.1.4.3;Creating the Model;523
9.1.4.3.1;Implementing the Repository Pattern;523
9.1.4.4;Defining the View;526
9.1.4.5;Defining the Controller;527
9.1.4.6;Completing the Framework;530
9.1.4.7;Running the Application;531
9.1.4.8;Extending the Application;532
9.1.4.8.1;Defining the New Commands;533
9.1.4.8.2;Defining the New View;534
9.1.4.8.3;Defining the New Controller;535
9.1.4.8.4;Updating the Framework;536
9.1.4.8.5;Testing the Changes;537
9.1.5;Variations on the MVC Pattern;537
9.1.6;Understanding the Pitfalls of the MVC Pattern;537
9.1.7;Examples of the MVC Pattern in Cocoa;538
9.1.8;Summary;538
10;Index;539