Get hands-on experience with each Gang of Four (GoF) design pattern using C#. For each of the patterns, you will see at least one real-world scenario, a coding example, and a complete implementation including output. In addition to GoF patterns, you will learn additional design patterns which are common and equally important.
In this second edition, you will go through the design patterns and their implementation in Visual Studio 2019 and C# 8. Common patterns in asynchronous programming are covered, including the TAP pattern and APM pattern. You will learn via easy-to-follow examples and understand the concepts in depth. With these updated patterns, you will have a collection of programs to port over to your own projects.
The book begins with the 23 GoF design patterns, and then moves onto alternative design patterns, including the Simple Factory, Null Object, and MVC patterns plus various patterns in asynchronous programming. The book concludes with a discussion of the criticisms of design patterns and chapters on anti-patterns.
Each chapter includes a Q&A session that clears up any doubts and covers the pros and cons of each pattern. FAQs will help you consolidate your knowledge.
What You Will Learn
Work with each of the design patterns
Implement the design patterns in real-world applications
Select an alternative to these patterns by comparing their pros and cons
Use Visual Studio Community Edition 2019 to write code and generate output
Who This Book Is For
Software developers, testers, and architects
Author(s): Vaskaran Sarcar
Edition: 2
Publisher: Apress
Year: 2020
Language: English
Pages: 676
Table of Contents
About the Author
About the Technical Reviewers
Foreword
Acknowledgments
Preface
Part I: Gang of Four Design Patterns
Part I.A: Creational Patterns
Chapter 1: Singleton Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Analysis
Q&A Session
Alternative Implementation
Analysis
Q&A Session
Chapter 2: Prototype Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Modified Implementation
Class Diagram
Demonstration 2
Output
Analysis
Q&A Session
Shallow Copy vs. Deep Copy
Demonstration 3
Output from a Shallow Copy
Analysis
Output from Deep Copy
Analysis
Q&A Session
Demonstration 4
Output
Analysis
Chapter 3: Builder Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Analysis
Q&A Session
An Alternative Implementation
Class Diagram
Solution Explorer View
Demonstration 2
Output
Analysis
Q&A Session
Chapter 4: Factory Method Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Modified Implementation 1
Partial Demonstration 1
Output
Analysis
Q&A Session
Modified Implementation 2
Partial Demonstration 2
Output
Chapter 5: Abstract Factory Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Q&A Session
Part I.B: Structural Patterns
Chapter 6: Proxy Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Q&A Session
Demonstration 2
Output
Chapter 7: Decorator Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration
Output
Q&A Session
Chapter 8: Adapter Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Analysis
Types of Adapters
Object Adapters
Class Adapters
Q&A Session
Demonstration 2
Output
Analysis
Q&A Session
Chapter 9: Facade Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration
Output
Q&A Session
Chapter 10: Flyweight Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Analysis
Q&A Session
Demonstration 2
Output
Analysis
Chapter 11: Composite Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration
Output
Q&A Session
Chapter 12: Bridge Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Additional Implementation
Class Diagram
Demonstration 2
Output
Q&A Session
Part I.C: Behavioral Patterns
Chapter 13: Visitor Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Q&A Session
Using Visitor Pattern and Composite Pattern Together
Step 1
Step 2
Step 3
Step 4
Step 5
Demonstration 2
Output
Chapter 14: Observer Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration
Output
Q&A Session
Chapter 15: Strategy Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration
Output
Q&A Session
Chapter 16: Template Method Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Q&A Session
Demonstration 2
Output
Chapter 17: Command Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Q&A Session
Modified Implementation
Demonstration 2
Output
Chapter 18: Iterator Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Demonstration 2
Output
Q&A Session
Chapter 19: Memento Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Analysis
Q&A Session
Modified Implementation
Class Diagram
Solution Explorer View
Demonstration 2
Output
Chapter 20: State Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration
Output
Q&A Session
Chapter 21: Mediator Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Analysis
Q&A Session
Modified Implementation
Demonstration 2
Output
Chapter 22: Chain of Responsibility Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration
Output
Q&A Session
Chapter 23: Interpreter Pattern
GoF Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Output
Another Implementation
Class Diagram
Solution Explorer View
Demonstration 2
Output
Q&A Session
Part II: Additional Design Patterns
Chapter 24: Simple Factory Pattern
Definition
Concept
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration
Output
Q&A Session
Chapter 25: Null Object Pattern
Definition
Concept
A Faulty Program
Output with Valid Input
Analysis with an Unwanted Input
A Potential Fix
Analysis
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration
Output
Analysis
Q&A Session
Chapter 26: MVC Pattern
Definition
Concept
Key Points to Remember
Variation 1
Variation 2
Variation 3
Real-World Example
Computer-World Example
Implementation
Class Diagram
Solution Explorer View
Demonstration 1
Contents in Model folder
Contents in View folder
Contents in Controller folder
Client code
Output
Q&A Session
Modified Output
Chapter 27: Patterns in Asynchronous Programming
Overview
Using Synchronous Approach
Demonstration 1
Output
Using Thread Class
Demonstration 2
Output
Analysis
Q&A Session
Using ThreadPool Class
Demonstration 3
Output
Q&A Session
Using Lambda Expression with the ThreadPool Class
Demonstration 4
Output
Using IAsyncResult Pattern
Polling Using Asynchronous Delegates
Demonstration 5
Output
Q&A Session
Using AsyncWaitHandle of IAsyncResult
Demonstration 6
Output
Analysis
Using Asynchronous Callback
Demonstration 7
Output
Analysis
Q&A Session
Using Event-based Asynchronous Pattern
Demonstration 8
Output
Analysis
Additional Note
Output
Q&A Session
Understanding Tasks
Demonstration 9
Output
Q&A Session
Using Task-based Asynchronous Pattern (TAP)
Demonstration 10
Output
Demonstration 11
Output
Analysis
Q&A Session
Using the async and await Keywords
Demonstration 12
Output
Analysis
Demonstration 13
Output
Analysis
Part III: Final Thoughts on Design Patterns
Chapter 28: Criticisms of Design Patterns
Q&A Session
Chapter 29: AntiPatterns
Overview
A Brief History of AntiPatterns
Examples of AntiPatterns
Types of AntiPatterns
Q&A Session
Chapter 30: FAQ
Appendix A:
A Brief Overview of GoF Design Patterns
Q&A Session
Appendix B:
Useful Resources
Appendix C:
The Road Ahead
Appendix D:
Important Updates in the Second Edition
Index