Use the step-by-step approach of this book to learn and implement design patterns in real-world applications. It focuses on classical design patterns with Java 17 and Eclipse (2021-09). In addition to Gang of Four (GoF) design patterns, the book covers popular and alternative design patterns and includes criticisms of design patterns in a chapter on anti-patterns.
The book is divided into four parts. Part one covers the SOLID design principles and the Simple Factory pattern. Part two covers the 23 (GoF) design patterns, including the creational patterns, structural patterns, and behavioral patterns. Part three covers alternative design patterns, including the Null Object pattern, and the model-view-controller (MVC) pattern. Part four covers criticisms of design patterns with a quick overview of anti-patterns. It also includes a chapter on FAQs on design patterns.
The book also includes a chapter on FAQs on design patterns. Each pattern is explained with real-world examples and the pros and cons of each of the design patterns are discussed. The book concludes with FAQs that can help you prepare for a job interview.
What You Will Learn
- Know the SOLID design principles in depth
- Implement the 23 design patterns from the GoF
Apply the Null Object pattern, Simple Factory pattern, and the MVC pattern- Know the criticism of design patterns
- Understand the anti-patterns
- Verify your understanding through Q&A sessions
- Select an alternative to these patterns by comparing their pros and cons
Who This Book Is For
Software developers, architects, and programmers
Author(s): Vaskaran Sarcar
Edition: 3
Publisher: Apress
Year: 2022
Language: English
Pages: 696
Tags: Java; Java 17; Design Patterns; Object-Oriented Programming
Table of Contents
About the Author
About the Technical Reviewers
Acknowledgments
Introduction
Chapter 1: Understanding SOLID Principles
Single Responsibility Principle
Initial Program
Demonstration 1
Output
Analysis
Better Program
Demonstration 2
Output
Open/Closed Principle
Initial Program
Demonstration 3
Output
Analysis
Better Program
Demonstration 4
Output
Analysis
Liskov Substitution Principle
Initial Program
Demonstration 5
Output
Better Program
Demonstration 6
Output
Analysis
Interface Segregation Principle
Initial Program
Demonstration 7
Output
Analysis
Better Program
Demonstration 8
Output
Analysis
Dependency Inversion Principle
Initial Program
Demonstration 9
Output
Analysis
Better Program
Demonstration 10
Output
Analysis
Summary
Chapter 2: Simple Factory Pattern
Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration
Output
Analysis
Q&A Session
Final Comment
Chapter 3: Factory Method Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Modified Implementation
Demonstration 2
Output
Analysis
Q&A Session
Chapter 4: Abstract Factory Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Analysis
The Client Code Variations
Demonstration 2
Demonstration 3
Q&A Session
Chapter 5: Prototype Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Modified Implementation
Class Diagram
Demonstration 2
Output
Analysis
Further Improvements
Q&A Session
Shallow Copy vs. Deep Copy
Demonstration 3
Output From Shallow Copy Implementation
Analysis
Output From Deep Copy Implementation
Analysis
Q&A Session Continued
Demonstration 4
Output
Analysis
Chapter 6: Builder Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Q&A Session
Alternative Implementation
Demonstration 2
Output
Analysis
Q&A Session Continued
Chapter 7: Singleton Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Analysis
Q&A Session
Alternative Implementations
Demonstration 2: Eager Initialization
Analysis
Demonstration 3: Bill Pugh’s Solution
Analysis
Demonstration 4: Enum Singleton
Analysis
Q&A Session Continued
Chapter 8: Proxy Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Q&A Session
Demonstration 2
Output
Chapter 9: Decorator Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Using Subclassing
Using Object Composition
Class Diagram
Package Explorer View
Demonstration
Output
Q&A Session
Chapter 10: Adapter Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Analysis
Types of Adapters
Object Adapters
Class Adapters
Q&A Session
Demonstration 2
Output
Analysis
Chapter 11: Facade Pattern
GoF Definition
Concept
Real-World Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration
Output
Analysis
Q&A Session
Chapter 12: Flyweight Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration
Output
Analysis
Q&A Session
Chapter 13: Composite Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration
Output
Analysis
Q&A Session
Chapter 14: Bridge Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Additional Implementation
Class Diagram
Demonstration 2
Output
Q&A Session
Chapter 15: Template Method Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Q&A Session
Demonstration 2
Output
Chapter 16: Observer Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration
Output
Q&A Session
Chapter 17: Chain of Responsibility Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration
Output
Q&A Session
Chapter 18: Iterator Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Additional Comments
Demonstration 2
Output
Q&A Session
Demonstration 3
Output
Chapter 19: Command Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Q&A Session
Modified Implementation
Class Diagram
Demonstration 2
Output
Chapter 20: Memento Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Analysis
Q&A Session
Additional Implementation
Class Diagram
Package Explorer View
Demonstration 2
Output
Analysis
Chapter 21: Strategy Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration
Output
Q&A Session
Chapter 22: State Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration
Output
Analysis
Q&A Session
Chapter 23: Mediator Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Analysis
Additional Implementation
Demonstration 2
Output
Analysis
Q&A Session
Chapter 24: Visitor Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Analysis
Using Visitor Pattern and Composite Pattern Together
Step 1
Step 2
Step 3
Step 4
Step 5
Demonstration 2
Output
Analysis
Demonstration 3
Output
Q&A Session
Chapter 25: Interpreter Pattern
GoF Definition
Concept
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration 1
Output
Analysis
Q&A Session
Alternative Implementation
Demonstration 2
Output
Chapter 26: Null Object Pattern
Definition
Concept
A Faulty Program
Output
An Unwanted Input
The Potential Fix
Analysis
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration
Output
Analysis
Q&A Session
Chapter 27: MVC Pattern
Definition
Concept
Key Points to Remember
Variation 1
Variation 2
Variation 3
Real-Life Example
Computer World Example
Implementation
Class Diagram
Package Explorer View
Demonstration
Contents in Model Folder
// Employee.java
// Model.java
// EmployeeModel.java
Contents in View Folder
// View.java
// ConsoleView.java
Contents in Controller Folder
// Controller.java
// EmployeeController.java
Client Code
// Client.java
Output
Q&A Session
Modified Output
Analysis
Chapter 28: Criticisms of Design Patterns
Q&A Session
Chapter 29: Anti-Patterns
Overview
Brief History of Anti-Patterns
Examples of Anti-Patterns
Types of Anti-Patterns
Q&A Session
Chapter 30: FAQ
Appendix A: A Brief Overview of
GoF Design Patterns
Q&A Session
Appendix B: The Road Ahead
A Personal Appeal to You
Appendix C: Recommended Reading
Index