Java Design Patterns (eBook)
XXXIII, 500 Seiten
Apress (Verlag)
978-1-4842-4078-6 (ISBN)
Get hands-on experience implementing 26 of the most common design patterns using Java and Eclipse. In addition to Gang of Four (GoF) design patterns, you will also learn about alternative design patterns, and understand the criticisms of design patterns with an overview of anti-patterns. For each pattern you will see at least one real-world scenario, a computer-world example, and a complete implementation including output.
This book has three parts. The first part covers 23 Gang of Four (GoF) design patterns. The second part includes three alternative design patterns. The third part presents criticisms of design patterns with an overview of anti-patterns. You will work through easy-to-follow examples to understand the concepts in depth and you will have a collection of programs to port over to your own projects.
A Q&A session is included in each chapter and covers the pros and cons of each pattern. The last chapter presents FAQs about the design patterns. The step-by-step approach of the book helps you apply your skills to learn other patterns on your own, and to be familiar with the latest version of Java and Eclipse.
What You'll Learn
- Work with each of the design patterns
- Implement design patterns in real-world applications
- Choose from alternative design patterns by comparing their pros and cons
- Use the Eclipse IDE to write code and generate output
- Read the in-depth Q&A session in each chapter with pros and cons for each design pattern
Get hands-on experience implementing 26 of the most common design patterns using Java and Eclipse. In addition to Gang of Four (GoF) design patterns, you will also learn about alternative design patterns, and understand the criticisms of design patterns with an overview of anti-patterns. For each pattern you will see at least one real-world scenario, a computer-world example, and a complete implementation including output.This book has three parts. The first part covers 23 Gang of Four (GoF) design patterns. The second part includes three alternative design patterns. The third part presents criticisms of design patterns with an overview of anti-patterns. You will work through easy-to-follow examples to understand the concepts in depth and you will have a collection of programs to port over to your own projects.A Q&A session is included in each chapter and covers the pros and cons of each pattern. The last chapter presents FAQs about the design patterns. The step-by-step approach of the book helps you apply your skills to learn other patterns on your own, and to be familiar with the latest version of Java and Eclipse.What You'll Learn Work with each of the design patternsImplement design patterns in real-world applicationsChoose from alternative design patterns by comparing their pros and consUse the Eclipse IDE to write code and generate outputRead the in-depth Q&A session in each chapter with pros and cons for each design patternWho This Book Is For Software developers, architects, and programmers
Vaskaran Sarcar obtained his Master of Engineering degree from Jadavpur University, Kolkata, in Software Engineering. Currently, he is Senior Software Engineer and Team Lead in the R&D Hub at HP Inc. India. He was a national Gate Scholar and has more than 12 years of experience in education and the IT industry. He is an alumnus of prestigious institutions in India such as Jadavpur University, Vidyasagar University, and Presidency University (formerly Presidency College). Reading and learning new things are his passions. You can connect to Vaskaran on LinkedIn.Other books by Vaskaran include the following: Design Patterns in C# (Apress), Interactive C# (Apress), Interactive Object-Oriented Programming in Java (Apress), Java Design Patterns (First Edition) (Apress), C# Basics: Test Your Skill, and Operating System: Computer Science Interview Series.
Table of Contents 5
About the Author 19
About the Technical Reviewers 20
Acknowledgments 22
Foreword 23
Introduction 24
Part I: Gang of Four Patterns 31
Chapter 1: Singleton Pattern 32
GoF Definition 32
Concept 32
Real-World Example 32
Computer-World Example 33
Illustration 33
Class Diagram 33
Package Explorer View 34
Discussion 34
Implementation 35
Output 36
Q& A Session
Output 40
Eager Initialization 41
Discussion 41
Output 43
Analysis 43
Bill Pugh’s Solution 43
Double-Checked Locking 44
Chapter 2: Prototype Pattern 47
GoF Definition 47
Concept 47
Real-World Example 47
Computer-World Example 48
Illustration 48
Class Diagram 48
Package Explorer View 50
Implementation 51
Output 53
Q& A Session
Demonstration 57
Output 59
Chapter 3: Builder Pattern 60
GoF Definition 60
Concept 60
Real-World Example 61
Computer-World Example 61
Illustration 62
Class Diagram 63
Package Explorer View 63
Implementation 65
Output 69
Q& A Session
Modified Illustration 73
Modified Package Explorer View 73
Modified Implementation 75
Modified Output 79
Analysis 80
Chapter 4: Factory Method Pattern 82
GoF Definition 82
Concept 82
Real-World Example 83
Computer-World Example 83
Illustration 84
Class Diagram 84
Package Explorer View 85
Implementation 85
Output 88
Modified Implementation 88
Modified Output 90
Analysis 90
Q& A Session
Chapter 5: Abstract Factory Pattern 94
GoF Definition 94
Concept 94
Real-World Example 95
Computer-World Example 95
Illustration 95
Class Diagram 97
Package Explorer View 98
Implementation 99
Output 103
Q& A Session
Simple Factory Pattern Code Snippet 104
Factory Method Pattern Code Snippet 105
Abstract Factory Pattern Code Snippet 105
Conclusion 106
Modified Illustration 107
Modified Implementation 107
Modified Output 112
Chapter 6: Proxy Pattern 113
GoF Definition 113
Concept 113
Real-World Example 113
Computer-World Example 114
Illustration 114
Class Diagram 114
Package Explorer View 115
Implementation 116
Output 118
Q& A Session
Alternate Implementation 119
Output Without Lazy Instantiation 121
Analysis 122
Output with Lazy Instantiation 122
Analysis 122
Modified Package Explorer View 124
Modified Implementation 125
Modified Output 127
Chapter 7: Decorator Pattern 129
GoF Definition 129
Concept 129
Real-World Example 129
Computer-World Example 131
Illustration 132
Class Diagram 132
Package Explorer View 133
Implementation 133
Output 136
Q& A Session
Chapter 8: Adapter Pattern 143
GoF Definition 143
Concept 143
Real-World Example 143
Computer-World Example 144
Illustration 145
Class Diagram 146
Package Explorer View 146
Implementation 147
Output 149
Modified Illustration 149
Modified Class Diagram 149
Key Characteristics of the Modified Implementation 150
Modified Package Explorer View 152
Modified Implementation 153
Modified Output 156
Types of Adapters 156
Object Adapters 156
Class Adapters 157
Q& A Session
Chapter 9: Facade Pattern 161
GoF Definition 161
Concept 161
Real-World Example 161
Computer-World Example 162
Illustration 162
Class Diagram 163
Package Explorer View 164
Implementation 165
Output 169
Q& A Session
Chapter 10: Flyweight Pattern 173
GoF Definition 173
Concept 173
Real-World Example 174
Computer-World Example 174
Illustration 175
Class Diagram 176
Package Explorer View 176
Implementation 177
Output 183
Analysis 185
Q& A Session
Chapter 11: Composite Pattern 190
GoF Definition 190
Concept 190
Real-World Example 191
Computer-World Example 191
Illustration 191
Class Diagram 192
Package Explorer View 193
Implementation 194
Output 199
Q& A Session
Chapter 12: Bridge Pattern 204
GoF Definition 204
Concept 204
Real-World Example 204
Computer-World Example 205
Illustration 205
Class Diagram 208
Package Explorer View 209
Key Characteristics 210
Implementation 210
Output 214
Q& A Session
Chapter 13: Visitor Pattern 217
GoF Definition 217
Concept 217
Real-World Example 218
Computer-World Example 218
Illustration 218
Class Diagram 219
Package Explorer View 220
Implementation 220
Output 222
Modified Illustration 222
Key Characteristic of the Modified Example 223
Step 1 224
Step 2 224
Step 3 225
Step 4 226
Step 5 226
Modified Class Diagram 228
Modified Package Explorer View 228
Modified Implementation 230
Modified Output 236
Q& A Session
Chapter 14: Observer Pattern 240
GoF Definition 240
Concept 240
Real-World Example 243
Computer-World Example 243
Illustration 244
Class Diagram 245
Package Explorer View 245
Implementation 247
Output 250
Analysis 250
Q& A Session
Chapter 15: Strategy (Policy) Pattern 255
GoF Definition 255
Concept 255
Real-World Example 255
Computer world Example 256
Illustration 256
Class Diagram 257
Package Explorer View 257
Implementation 259
Output 262
Q& A Session
Chapter 16: Template Method Pattern 272
GoF Definition 272
Concept 272
Real-World Example 272
Computer-World Example 273
Illustration 273
Class Diagram 273
Package Explorer View 274
Implementation 275
Output 277
Q& A Session
Modified Implementation 278
Modified Output 281
Chapter 17: Command Pattern 283
GoF Definition 283
Concept 283
Real-World Example 283
Computer-World Example 284
Illustration 284
Class Diagram 285
Package Explorer View 286
Implementation 287
Output 290
Q& A Session
Modified Class Diagram 291
Modified Package Explorer View 292
Modified Implementation 294
Modified Output 300
Chapter 18: Iterator Pattern 304
GoF Definition 304
Concept 304
Real-World Example 305
Computer-World Example 306
Illustration 306
Class Diagram 307
Package Explorer View 309
First Implementation 310
Output 312
Key Characteristics of the Second Implementation 313
Second Implementation 313
Output 315
Q& A Session
Third Implementation 318
Output 321
Chapter 19: Memento Pattern 322
GoF Definition 322
Concept 322
Real-World Example 322
Computer-World Example 323
Illustration 323
Class Diagram 324
Package Explorer View 325
Implementation 325
Output 328
Q& A Session
Modified Caretaker Class 330
Modified Output 331
Analysis 332
Shallow Copy vs. Deep Copy in Java 340
Key Characteristics of the Following Program 340
Implementation 341
Output 344
Analysis 344
Modified Output 345
Analysis 345
Chapter 20: State Pattern 347
GoF Definition 347
Concept 347
Real-World Example 348
Computer-World Example 348
Illustration 348
Key Characteristics 350
Class Diagram 350
Package Explorer View 352
Implementation 353
Output 357
Q& A Session
Modified Package Explorer View 361
Modified Implementation 363
Modified Output 368
Chapter 21: Mediator Pattern 371
GoF Definition 371
Concept 371
Real-World Example 371
Computer-World Example 372
Illustration 373
Class Diagram 374
Package Explorer View 375
Implementation 377
Output 381
Analysis 381
Modified Illustration 381
Modified Class Diagram 383
Modified Package Explorer View 384
Modified Implementation 385
Modified Output 390
Analysis 391
Q& A Session
Chapter 22: Chain-of-Responsibility Pattern 395
GoF Definition 395
Concept 395
Real-World Example 396
Computer-World Example 396
Illustration 397
Class Diagram 398
Package Explorer View 399
Implementation 400
Output 403
Q& A Session
Chapter 23: Interpreter Pattern 406
GoF Definition 406
Concept 406
Real-World Example 408
Computer-World Example 408
Illustration 408
Class Diagram 410
Package Explorer View 411
Implementation 412
Output 416
Analysis 417
Modified Illustration 417
Modified Class Diagram 417
Modified Package Explorer View 417
Modified Implementation 418
Modified Output 423
Analysis 423
Q& A Session
Part II: Additional Design Patterns 425
Chapter 24: Simple Factory Pattern 426
Intent 426
Concept 426
Real-World Example 426
Computer-World example 427
Illustration 428
Class Diagram 428
Package Explorer View 429
Implementation 430
Output 432
Case1. User input:0 433
Case2. User input:1 433
Case3. An unwanted user input:2 433
Q& A Session
Chapter 25: Null Object Pattern 436
Concept 436
A Faulty Program 437
Output with Valid Inputs 439
Analysis with an Unwanted Input 439
Encountered Exception 440
Immediate Remedy 440
Analysis 440
Real-World Example 441
Computer-World Example 441
Illustration 441
Class Diagram 442
Package Explorer View 443
Implementation 444
Output 447
Analysis 448
Q& A Session
Chapter 26: MVC Pattern 452
Concept 452
Key Points to Remember 453
Variation 1 454
Variation 2 454
Variation 3 455
Real-World Example 455
Computer-World Example 456
Illustration 457
Class Diagram 457
Package Explorer View 459
Implementation 459
Output 467
Q& A Session
Modified Output 470
Part III: Final Discussions on Design Patterns 473
Chapter 27: Criticisms of Design Patterns 474
Q& A Session
Chapter 28: AntiPatterns: Avoid the Common Mistakes 480
What Is an Antipattern? 480
Brief History of Antipatterns 481
Examples of Antipatterns 482
Types of Antipatterns 484
Q& A Session
Chapter 29: FAQs 488
Appendix A: A Brief Overview of GoF Design Patterns 494
Key Points 495
A. Creational Patterns 496
B. Structural Patterns 496
C. Behavioral Patterns 497
Q& A Session
Appendix B: Winning Notes and the Road Ahead 502
Appendix C: Bibliography 503
Index 505
Erscheint lt. Verlag | 6.12.2018 |
---|---|
Zusatzinfo | XXXIII, 500 p. 128 illus. |
Verlagsort | Berkeley |
Sprache | englisch |
Themenwelt | Informatik ► Programmiersprachen / -werkzeuge ► Java |
Informatik ► Software Entwicklung ► Objektorientierung | |
Schlagworte | Behavioural Pattern • Composite Pattern • Design Patterns • Java • Observer Pattern • Singleton Pattern • structural pattern |
ISBN-10 | 1-4842-4078-2 / 1484240782 |
ISBN-13 | 978-1-4842-4078-6 / 9781484240786 |
Haben Sie eine Frage zum Produkt? |
Größe: 17,6 MB
DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasserzeichen und ist damit für Sie personalisiert. Bei einer missbräuchlichen Weitergabe des eBooks an Dritte ist eine Rückverfolgung an die Quelle möglich.
Dateiformat: PDF (Portable Document Format)
Mit einem festen Seitenlayout eignet sich die PDF besonders für Fachbücher mit Spalten, Tabellen und Abbildungen. Eine PDF kann auf fast allen Geräten angezeigt werden, ist aber für kleine Displays (Smartphone, eReader) nur eingeschrä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.
aus dem Bereich