Nicht aus der Schweiz? Besuchen Sie lehmanns.de
Pro Design Patterns in Swift - Adam Freeman

Pro Design Patterns in Swift (eBook)

(Autor)

eBook Download: PDF
2015 | 1st ed.
XXIV, 592 Seiten
Apress (Verlag)
978-1-4842-0394-1 (ISBN)
Systemvoraussetzungen
52,99 inkl. MwSt
(CHF 51,75)
Der eBook-Verkauf erfolgt durch die Lehmanns Media GmbH (Berlin) zum Preis in Euro inkl. MwSt.
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

The Swift programming language has transformed the world of iOS development and started a new age of modern development. Pro Design Patterns in Swift shows you how to harness the power and flexibility of Swift to apply the most important and enduring design patterns to your applications, taking your development projects to master level.

This book will teach you those design patterns that have always been present at some level in your code, but may not have been recognized, acknowledged, or fully utilized. Implementation of specific pattern approaches will prove their value to any Swift developer.

Best-selling author Adam Freeman explains how to get the most from design patterns. He starts with the nuts-and-bolts and shows you everything through to advanced features, going in-depth to give you the knowledge you need.

Pro Design Patterns in Swift brings design patterns to life and shows you how to bring structure and scale to your Swift code with a practical, no-nonsense approach.



Adam Freeman is an experienced IT professional who has held senior positions in a range of companies, most recently serving as chief technology officer and chief operating officer of a global bank. Now retired, he spends his time writing and long-distance running.
The Swift programming language has transformed the world of iOS development and started a new age of modern development. Pro Design Patterns in Swift shows you how to harness the power and flexibility of Swift to apply the most important and enduring design patterns to your applications, taking your development projects to master level.This book will teach you those design patterns that have always been present at some level in your code, but may not have been recognized, acknowledged, or fully utilized. Implementation of specific pattern approaches will prove their value to any Swift developer.Best-selling author Adam Freeman explains how to get the most from design patterns. He starts with the nuts-and-bolts and shows you everything through to advanced features, going in-depth to give you the knowledge you need. Pro Design Patterns in Swift brings design patterns to life and shows you how to bring structure and scale to yourSwift code with a practical, no-nonsense approach.

Adam Freeman is an experienced IT professional who has held senior positions in a range of companies, most recently serving as chief technology officer and chief operating officer of a global bank. Now retired, he spends his time writing and long-distance running.

Contents at a Glance 3
Contents 550
About the Author 567
About the Technical Reviewer 568
Part I: Getting Ready 5
Chapter 1: Understanding Design Patterns 6
Putting Design Patterns into Context 6
Introducing Design Patterns 7
Understanding the Structure of a Design Pattern 7
Quantifying the Value of Design Patterns 8
Using a Design Pattern After the Problem Occurred 9
Understanding the Limitations of Design Patterns 9
About This Book 10
What Do You Need to Know? 10
What Software Do You Need? 10
What Is the Structure of This Book? 10
Where Can You Get the Example Code? 11
Summary 11
Chapter 2: Getting Used to Xcode 12
Working with Xcode Playgrounds 12
Creating a Playground 13
Displaying the Value History of a Variable 15
Using the Value Timeline 18
Displaying UI Components in a Playground 19
Working with OS X Command Line Tool Projects 21
Creating a Command-Line Project 21
Understanding the Xcode Layout 23
Adding a New Swift File 24
Summary 27
Chapter 3: Creating the SportsStore App 28
Creating an Unstructured iOS App Project 28
Creating the Project 30
Understanding the Xcode Layout 31
Defining the Data 31
Creating the Basic Layout 34
Adding the Basic Components 35
Configuring Auto Layout 37
Testing the Basic Layout 38
Implementing the Total Label 39
Creating the Reference 39
Updating the Display 41
Implementing the Table Cells 42
Defining the Custom Table Cell and Layout 43
Setting the Table Cell Layout Constraints 45
Creating the Table Cell Class and Outlets 45
Implementing the Data Source Protocol 47
Registering the Data Source 49
Testing the Data Source 49
Handling the Editing Actions 50
Handling the Events 51
Testing the SportsStore App 53
Summary 54
Part II: The Creation Patterns 55
Chapter 4: The Object Template Pattern 56
Preparing the Example Project 57
Understanding the Problem Addressed by the Pattern 57
Understanding the Object Template Pattern 60
Implementing the Object Template Pattern 61
Understanding the Benefits of the Pattern 62
The Benefit of Decoupling 62
The Benefit of Encapsulation 63
The Benefit of an Evolving Public Presentation 66
Understanding the Pitfalls of the Pattern 68
Examples of the Object Template Pattern in Cocoa 68
Applying the Pattern to the SportsStore App 68
Preparing the Example Application 69
Creating the Product Class 71
Applying the Product Class 73
Ensuring View and Model Separation 75
Expanding the Summary Display 76
Summary 77
Chapter 5: The Prototype Pattern 78
Understanding the Problem Addressed by the Pattern 79
Incurring Expensive Initializations 79
Creating Template Dependencies 80
Understanding the Prototype Pattern 82
Implementing the Prototype Pattern 82
Cloning Reference Types 85
Implementing the NSCopying Protocol 86
Understanding Shallow and Deep Copying 88
Implementing Deep Copying 90
Copying Arrays 92
Understanding the Benefits of the Prototype Pattern 94
Avoiding Expensive Initializations 94
Separating Object Creation from Object Use 97
(Not Really) Solving the Problem 98
Revealing the Underlying Problem 99
(Not Really) Solving the Underlying Problem 101
Applying the Prototype Pattern 101
Understanding the Pitfalls of the Prototype Pattern 103
Understanding the Deep vs. Shallow Pitfall 103
Understanding the Exposure Distortion Pitfall 104
Understanding the Nonstandard Protocol Pitfall 104
Examples of the Prototype Pattern in Cocoa 104
Using Cocoa Arrays 104
Shallow Copying a Cocoa Array 106
Creating a Deep Copy of a Cocoa Array 106
Using the NSCopying Property Attribute 107
Applying the Pattern to the SportsStore App 108
Preparing the Example Application 109
Implementing NSCopying in the Product Class 109
Creating the Logger Class 110
Logging Changes in the View Controller 111
Testing the Changes 113
Summary 113
Chapter 6: The Singleton Pattern 114
Preparing the Example Project 115
Understanding the Problem That the Pattern Solves 115
Understanding the Shared Resource Encapsulation Problem 116
Understanding the Singleton Pattern 118
Implementing the Singleton Pattern 119
The Quick Singleton Implementation 119
Creating a Conventional Singleton Implementation 122
Dealing with Concurrency 123
Serializing Access 126
Understanding the Pitfalls of the Singleton Pattern 129
Understanding the Leakage Pitfall 129
Understanding the Shared Code File Pitfall 130
Understanding the Concurrency Pitfalls 130
Not Applying Concurrency Protections 130
Applying Concurrency Protections Consistently 130
Bad Optimization 130
Examples of the Singleton Pattern in Cocoa 131
Applying the Pattern to the SportsStore Application 131
Protecting the Data Array 132
Protecting the Callback 133
Defining the Singleton 134
Summary 137
Chapter 7: The Object Pool Pattern 138
Preparing the Example Project 139
Understanding the Problem That the Pattern Solves 139
Understanding the Object Pool Pattern 140
Implementing the Object Pool Pattern 142
Defining the Pool Class 142
Protecting the Data Array 143
Ensuring Objects Are Available to Be Checked Out 144
Consuming the Pool Class 146
Understanding the Pitfalls of the Object Pool Pattern 149
Examples of the Object Pool Pattern in Cocoa 149
Applying the Pattern to the SportsStore Application 150
Preparing the Example Application 151
Creating the (Fake) Server 151
Creating the Object Pool 151
Applying the Object Pool 153
Summary 156
Chapter 8: Object Pool Variations 157
Preparing the Example Project 158
Understanding the Object Pool Pattern Variations 158
Understanding the Object Creation Strategy 158
Understanding the Object Reuse Strategy 163
Applying the Protocol 165
Testing the Strategy 166
Understanding the Empty Pool Strategy 167
Implementing the Failing Request Strategy 168
Dealing with Exhausted Pools 172
Creating an Elastic Pool 175
Understanding the Allocation Strategy 179
Understanding the Pitfalls of the Pattern Variations 182
Understanding the Expectation Gap Pitfall 182
Understanding the Over- and Under-utilization Pitfalls 183
Examples of the Pattern Variations in Cocoa 183
Applying a Pattern Variation to SportsStore 183
Summary 185
Chapter 9: The Factory Method Pattern 186
Preparing the Example Project 187
Understanding the Problem That the Pattern Solves 188
Understanding the Factory Method Pattern 190
Implementing the Factory Method Pattern 191
Defining a Global Factory Method 192
Using a Base Class 193
Delegating Decisions for Deeper Class Hierarchies 195
Variations on the Factory Method Pattern 198
Understanding the Pitfalls of the Pattern 200
Examples of the Factory Method Pattern in Cocoa 200
Applying the Pattern to the SportsStore Application 201
Preparing the Example Application 201
Implementing the Factory Method Pattern 203
Consuming the Factory Method Pattern 204
Summary 205
Chapter 10: Abstract Factory Pattern 206
Preparing the Example Project 207
Understanding the Problem That the Pattern Solves 210
Understanding the Abstract Factory Pattern 211
Implementing the Abstract Factory Pattern 212
Creating the Abstract Factory 213
Creating the Concrete Factories 213
Completing the Abstract Factory 214
Consuming the Abstract Factory Pattern 215
Variations on the Abstract Factory Pattern 216
Hiding the Abstract Factory Class 216
Applying the Singleton Pattern to the Concrete Factories 218
Applying the Prototype Pattern to the Implementation Classes 219
Preparing the Example Application 220
Applying the Prototype Pattern 223
Understanding the Pitfalls of the Pattern 226
Examples of the Pattern in Cocoa 226
Applying the Pattern to the SportsStore Application 226
Preparing the Example Application 226
Defining the Implementation Protocols and Classes 227
Defining the Abstract and Concrete Factory Classes 228
Consuming the Factories and Implementation Classes 229
Summary 230
Chapter 11: The Builder Pattern 231
Preparing the Example Project 232
Understanding the Problems That the Pattern Solves 233
Understanding the Builder Pattern 236
Implementing the Builder Pattern 237
Defining the Builder Class 237
Consuming the Builder 238
Understanding the Impact of the Pattern 239
Changing the Process 240
Changing the Object 240
Avoiding Inconsistent Configurations 242
Variations on the Builder Pattern 243
Understanding the Pitfalls of the Builder Pattern 245
Examples of the Builder Pattern in Cocoa 245
Applying the Pattern to the SportsStore Application 246
Preparing the Example Application 246
Defining the Builder Class 247
Using the Builder Class 248
Summary 248
Part III: The Structural Patterns 249
Chapter 12: The Adapter Pattern 250
Preparing the Example Project 251
Creating the Data Sources 251
Defining the Application 252
Understanding the Problem That the Pattern Solves 254
Understanding the Adapter Pattern 255
Implementing the Adapter Pattern 256
Variations on the Adapter Pattern 258
Defining an Adapter as a Wrapper Class 259
Creating a Two-Way Adapter 260
Understanding the Pitfalls of the Adapter Pattern 263
Examples of the Adapter Pattern in Cocoa 263
Applying the Pattern to the SportsStore Application 264
Preparing the Example Application 264
Defining the Adapter Class 264
Using the Adapted Functionality 266
Summary 267
Chapter 13: The Bridge Pattern 268
Preparing the Example Project 269
Understanding the Problem That the Pattern Solves 271
Understanding the Bridge Pattern 272
Implementing the Bridge Pattern 274
Dealing with the Messages 274
Dealing with the Channels 275
Creating the Bridge 276
Adding a New Message Type and Channel 277
Variations on the Bridge Pattern 281
Collapsing the Bridge 283
Understanding the Pitfalls of the Bridge Pattern 285
Examples of the Bridge Pattern in Cocoa 285
Applying the Pattern to the SportsStore Application 285
Preparing the Example Application 285
Understanding the Problem 286
Defining the Bridge Class 286
Summary 288
Chapter 14: The Decorator Pattern 289
Preparing the Example Project 290
Understanding the Problem That the Pattern Solves 291
Understanding the Decorator Pattern 294
Implementing the Decorator Pattern 294
Variations on the Decorator Pattern 296
Creating Decorators with New Functionality 296
Using the New Functionality 298
Understanding the Limitations of Decorators with New Functionality 299
Creating Consolidated Decorators 300
Understanding the Pitfalls of the Decorator Pattern 302
The Side-Effect Pitfall 302
Examples of the Decorator Pattern in Cocoa 303
Applying the Pattern to the SportsStore Application 303
Preparing the Example Application 303
Creating the Decorators 303
Applying the Decorators 304
Summary 305
Chapter 15: The Composite Pattern 306
Preparing the Example Project 307
Understanding the Problem That the Pattern Solves 309
Understanding the Composite Pattern 309
Implementing the Composite Pattern 310
Applying the Pattern 311
Understanding the Pitfalls of the Composite Pattern 313
Examples of the Composite Pattern in Cocoa 315
Applying the Pattern to the SportsStore Application 315
Preparing the Example Application 315
Defining the Composite Class 316
Applying the Pattern 317
Summary 318
Chapter 16: The Façade Pattern 319
Preparing the Example Project 320
Understanding the Problem That the Pattern Solves 322
Understanding the Façade Pattern 323
Implementing the Façade Pattern 324
Applying the Façade 325
Variations on the Façade Pattern 326
Understanding the Pitfalls of the Façade Pattern 327
Examples of the Façade Pattern in Cocoa 327
Applying the Pattern to the SportsStore Application 329
Preparing the Example Application 330
Creating the Façade Class 330
Applying the Façade Class 331
Summary 332
Chapter 17: The Flyweight Pattern 333
Preparing the Example Project 334
Understanding the Problems That the Pattern Solves 335
Understanding the Flyweight Pattern 336
Implementing the Flyweight Pattern 337
Creating the Flyweight Protocol 337
Creating the Flyweight Implementation Class 338
Adding Concurrency Protections 339
Creating the Flyweight Factory Class 341
Applying the Flyweight 342
Variations on the Flyweight Pattern 344
Understanding the Pitfalls of the Flyweight Pattern 346
Understanding the Extrinsic Duplication Pitfall 346
Understanding the Mutable Extrinsic Data Pitfall 346
Understanding the Concurrent Access Pitfall 346
Understanding the Over-optimization Pitfall 346
Understanding the Misapplication Pitfall 347
Examples of the Flyweight Pattern in Cocoa 347
Applying the Pattern to the SportsStore Application 348
Preparing the Example Application 348
Creating the Flyweight Protocol and Implementation Class 348
Creating the Flyweight Factory 349
Applying the Flyweight 350
Summary 350
Chapter 18: The Proxy Pattern 351
Preparing the Example Project 352
Understanding the Problems That the Pattern Solves 353
Understanding the Remote Object Problem 353
Understanding the Expensive Operation Problem 353
Understanding the Restricted Access Problem 353
Understanding the Proxy Pattern 353
Solving the Remote Object Problem 354
Solving the Expensive Operation Problem 355
Solving the Restricted Access Problem 355
Implementing the Proxy Pattern 356
Implementing the Remote Object Proxy 356
Defining the Proxy Protocol 356
Defining the Proxy Implementation Class 357
Using the Remote Object Proxy 358
Implementing the Expensive Operation Proxy 358
Deferring the Operation 360
Implementing the Access Restriction Proxy 362
Creating the Authorization Source 362
Creating the Proxy Object 363
Applying the Proxy 364
Variations on the Proxy Pattern 364
Implementing a Reference Counting Proxy 367
Understanding the Pitfalls of the Proxy Pattern 369
Examples of the Proxy Pattern in Cocoa 369
Applying the Pattern to the SportsStore Application 369
Preparing the Example Application 370
Defining the Protocol, Factory Method, and Proxy Class 370
Updating the Product Data Store 371
Sending Stock Level Updates 372
Summary 374
Part IV: The Behavioral Patterns 375
Chapter 19: The Chain of Responsibility Pattern 376
Preparing the Example Project 377
Understanding the Problem That the Pattern Solves 379
Understanding the Chain of Responsibility Pattern 380
Implementing the Chain of Responsibility Pattern 381
Creating and Providing the Chain of Responsibility 382
Applying the Chain of Responsibility Pattern 383
Variations on the Chain of Responsibility Pattern 384
Applying the Factory Method Pattern 384
Indicating Whether Responsibility Was Taken for the Request 385
Notifying All Links in the Chain 387
Understanding the Pitfalls of the Pattern 389
Examples of the Pattern in Cocoa 389
Applying the Pattern to the SportsStore Application 390
Preparing the Example Application 390
Defining the Chain and its Links 390
Summary 392
Chapter 20: The Command Pattern 393
Preparing the Example Project 394
Understanding the Problem That the Pattern Solves 395
Understanding the Command Pattern 396
Implementing the Command Pattern 397
Defining the Command Protocol 397
Defining the Command Implementation Class 397
Applying the Command Pattern 398
Applying Concurrent Protections 400
Using the Undo Feature 402
Variations on the Command Pattern 403
Creating Composite Commands 403
Using Commands as Macros 405
Using Closures as Commands 407
Understanding the Pitfalls of the Command Pattern 410
Examples of the Command Pattern in Cocoa 410
Applying the Pattern to the SportsStore Application 410
Preparing the Example Application 410
Implementing the Undo Feature 411
Triggering an Undo Command 413
Summary 413
Chapter 21: The Mediator Pattern 414
Preparing the Example Project 415
Understanding the Problem That the Pattern Solves 417
Understanding the Mediator Pattern 419
Implementing the Mediator Pattern 420
Defining the Meditator Class 420
Conforming to the Peer Protocol 421
Implementing Concurrency Protections 423
Implementing Concurrency Protections in the Mediator 423
Implementing Concurrency Protections in the Peer 424
Variations on the Mediator Pattern 426
Putting More Logic Into the Mediator 426
Generalizing the Mediator-Peer Relationship 427
Generalizing the Mediator with the Command Pattern 427
Generalizing the Mediator with Messages 431
Understanding the Pitfalls of the Mediator Pattern 434
The Single Protocol Pitfall 435
Examples of the Mediator Pattern in Cocoa 435
Applying the Pattern to the SportsStore Application 437
Summary 437
Chapter 22: The Observer Pattern 438
Preparing the Example Project 439
Understanding the Problem That the Pattern Solves 440
Understanding the Observer Pattern 441
Implementing the Observer Pattern 442
Creating the Base Subject Class 443
Conforming to the Subject Protocol 444
Conforming to the Observer Protocol 445
Consuming the Pattern 446
Variations on the Observer Pattern 446
Generalizing Notifications 447
Understanding the Notification Object Pitfall 450
Using Weak References 452
Dealing with Short-Lived Subjects 454
Understanding the Pitfalls of the Observer Pattern 457
Examples of the Observer Pattern in Cocoa 457
User Interface Events 457
Observing Property Changes 458
Applying the Pattern to the SportsStore Application 459
Preparing the Example Application 459
Applying the Pattern 460
Summary 462
Chapter 23: The Memento Pattern 463
Preparing the Example Project 464
Understanding the Problem That the Pattern Solves 466
Understanding the Memento Pattern 466
Implementing the Memento Pattern 468
Implementing the Memento Class 468
Using the Memento 470
Variations on the Memento Pattern 471
Understanding the Pitfalls of the Memento Pattern 473
Examples of the Memento Pattern in Cocoa 474
Applying the Pattern to the SportsStore Application 477
Preparing the Example Application 478
Implementing the Pattern 478
Summary 480
Chapter 24: The Strategy Pattern 481
Preparing the Example Project 482
Understanding the Problem That the Pattern Solves 482
Understanding the Strategy Pattern 484
Implementing the Strategy Pattern 485
Defining the Strategies and the Context Class 485
Consuming the Pattern 486
Variations on the Strategy Pattern 487
Understanding the Pitfalls of the Strategy Pattern 488
Examples of the Strategy Pattern in Cocoa 488
Cocoa Protocol-Based Strategies 488
Cocoa Selector-Based Strategies 490
Applying the Pattern to the SportsStore Application 491
Summary 491
Chapter 25: The Visitor Pattern 492
Preparing the Example Project 493
Understanding the Problem That the Pattern Solves 494
Understanding the Visitor Pattern 496
Implementing the Visitor Pattern 497
Conforming to the Shape Protocol 500
Creating the Visitors 502
Applying the Visitors 503
Variations on the Visitor Pattern 503
Understanding the Pitfalls of the Visitor Pattern 503
Examples of the Visitor Pattern in Cocoa 504
Applying the Pattern to the SportsStore Application 504
Summary 504
Chapter 26: The Template Method Pattern 505
Preparing the Example Project 506
Understanding the Problem That the Pattern Solves 507
Understanding the Template Method Pattern 508
Implementing the Template Method Pattern 508
Variations on the Template Method Pattern 510
Understanding the Pitfalls of the Pattern 512
Examples of the Template Method Pattern in Cocoa 512
Applying the Pattern to the SportsStore Application 512
Summary 512
Part V: The MVC Pattern 513
Chapter 27: The Model/View/Controller Pattern 514
Preparing the Example Project 515
Understanding the Problem That the Pattern Solves 515
Understanding the MVC Pattern 515
Understanding the MVC Application Sections 517
Understanding the Model 518
Understanding Controllers 519
Understanding Views 519
Understanding Cross-Cutting Concerns 520
Implementing the MVC Pattern 520
Defining the Common Code 521
Defining the Framework 522
Creating the Model 523
Implementing the Repository Pattern 523
Defining the View 526
Defining the Controller 527
Completing the Framework 530
Running the Application 531
Extending the Application 532
Defining the New Commands 533
Defining the New View 534
Defining the New Controller 535
Updating the Framework 536
Testing the Changes 537
Variations on the MVC Pattern 537
Understanding the Pitfalls of the MVC Pattern 537
Examples of the MVC Pattern in Cocoa 538
Summary 538
Index 539

Erscheint lt. Verlag 17.1.2015
Zusatzinfo XXIV, 592 p. 95 illus.
Verlagsort Berkeley
Sprache englisch
Themenwelt Mathematik / Informatik Informatik Betriebssysteme / Server
Informatik Programmiersprachen / -werkzeuge Mac / Cocoa Programmierung
ISBN-10 1-4842-0394-1 / 1484203941
ISBN-13 978-1-4842-0394-1 / 9781484203941
Haben Sie eine Frage zum Produkt?
PDFPDF (Wasserzeichen)
Größe: 6,8 MB

DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasser­zeichen und ist damit für Sie persona­lisiert. Bei einer missbräuch­lichen Weiter­gabe des eBooks an Dritte ist eine Rück­ver­folgung an die Quelle möglich.

Dateiformat: PDF (Portable Document Format)
Mit einem festen Seiten­layout eignet sich die PDF besonders für Fach­bücher mit Spalten, Tabellen und Abbild­ungen. Eine PDF kann auf fast allen Geräten ange­zeigt werden, ist aber für kleine Displays (Smart­phone, eReader) nur einge­schränkt geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.

Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
A guide for building beautiful and interactive SwiftUI apps

von Juan C. Catalan

eBook Download (2023)
Packt Publishing (Verlag)
CHF 31,65
Einführung und Sprachreferenz

von Thomas Sillmann

eBook Download (2017)
Carl Hanser Verlag GmbH & Co. KG
CHF 35,15