Real-World Implementation of C# Design Patterns

Book description

Build robust applications in C# easily using effective and popular design patterns and best practices

Key Features

  • Recognize solutions to common problems in software design with C#
  • Explore real-world applications of design patterns that can be used in your everyday work
  • Get to grips with 14 patterns and their design implementations

Book Description

As a software developer, you need to learn new languages and simultaneously get familiarized with the programming paradigms and methods of leveraging patterns, as both a communications tool and an advantage when designing well-written, easy-to-maintain code. Design patterns, being a collection of best practices, provide the necessary wisdom to help you overcome common sets of challenges in object-oriented design and programming.

This practical guide to design patterns helps C# developers put their programming knowledge to work. The book takes a hands-on approach to introducing patterns and anti-patterns, elaborating on 14 patterns along with their real-world implementations. Throughout the book, you'll understand the implementation of each pattern, as well as find out how to successfully implement those patterns in C# code within the context of a real-world project.

By the end of this design patterns book, you’ll be able to recognize situations that tempt you to reinvent the wheel, and quickly avoid the time and cost associated with solving common and well-understood problems with battle-tested design patterns.

What you will learn

  • Get to grips with patterns, and discover how to conceive and document them
  • Explore common patterns that may come up in your everyday work
  • Recognize common anti-patterns early in the process
  • Use creational patterns to create flexible and robust object structures
  • Enhance class designs with structural patterns
  • Simplify object interaction and behavior with behavioral patterns

Who this book is for

This book is for beginner and mid-level software developers who are looking to take their object-oriented programs or software designing skills to the next level by learning to leverage common patterns. A firm grasp of programming fundamentals and classical object-oriented programming (OOP) using languages like C#, C++, Objective-C, or Java is expected.

Table of contents

  1. Real-World Implementation of C# Design Patterns
    1. Real-World Implementation of C# Design Patterns
  2. Foreword
  3. Contributors
    1. About the author
    2. About the reviewers
  4. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
  5. Part 1: Introduction to Patterns (Pasta) and Antipatterns (Antipasta)
  6. Chapter 1: There’s a Big Ball of Mud on Your Plate of Spaghetti
    1. Technical requirements
    2. No battle plan survives first contact with the enemy
      1. The Stovepipe system
    3. The Big Ball of Mud
      1. Time
      2. Cost
      3. Experience
      4. Skill
      5. Visibility
      6. Complexity
      7. Change
      8. Scale
    4. The Golden Hammer
    5. A throwaway code example
    6. How can patterns help?
    7. Summary
    8. Questions
    9. Further reading
  7. Chapter 2: Prepping for Practical Real-World Applications of Patterns in C#
    1. Becoming a prepper
    2. Technical requirements
    3. Spaghetti < lasagna < ravioli – software evolution explained with pasta
      1. Spaghetti code
      2. Lasagna code
      3. Ravioli – the ultimate in pasta code
    4. The foundational principle – writing clean code
      1. You should write code that is readable by humans
      2. Establishing and enforcing style and consistency
      3. Limiting cognitive load
      4. Terse is worse
      5. Comment but don’t go overboard
    5. Creating maintainable systems using SOLID principles
      1. The Single Responsibility principle
      2. The Open-Closed Principle
      3. The Liskov Substitution principle
      4. The Interface Segregation principle
      5. The Dependency Inversion principle
    6. Measuring quality beyond the development organization
      1. Code reviews
      2. Overall design
      3. Functionality
    7. Summary
    8. Further reading
  8. Part 2: Patterns You Need in the Real World
  9. Chapter 3: Getting Creative with Creational Patterns
    1. Technical requirements
    2. The following story is fictitious
    3. The initial design
    4. No pattern implementation
    5. The Simple Factory pattern
    6. The Factory Method pattern
    7. The Abstract Factory pattern
    8. The Builder pattern
    9. The Object Pool pattern
    10. The Singleton pattern
    11. Summary
    12. Questions
    13. Further reading
  10. Chapter 4: Fortify Your Code With Structural Patterns
    1. Technical requirements
    2. B2B (back to bicycles)
    3. The Decorator pattern
    4. The Façade pattern
    5. The Composite pattern
    6. The Bridge pattern
    7. Summary
    8. Questions
    9. Further reading
  11. Chapter 5: Wrangling Problem Code by Applying Behavioral Patterns
    1. Technical requirements
    2. Meanwhile, back at the bicycle factory
    3. The Command pattern
      1. Applying the Command pattern
      2. Coding the Command pattern
      3. Testing the Command pattern’s code
    4. The Iterator pattern
      1. Applying the Iterator pattern
      2. Coding the Iterator pattern
      3. Trying out the new iterator
    5. The Observer pattern
      1. Applying the Observer pattern
      2. Coding the Observer pattern
    6. The Strategy pattern
      1. Applying the Strategy pattern
      2. Coding the Strategy pattern
    7. Summary
    8. Questions
  12. Part 3: Designing New Projects Using Patterns
  13. Chapter 6: Step Away from the IDE! Designing with Patterns Before You Code
    1. Technical requirements
    2. A bad day at the agency
    3. Bumble Bikes factory – Dallas, Texas
    4. A physical rehabilitation clinic – Dallas, Texas
    5. Designing with patterns
    6. The first pass
      1. The seat
      2. The frame
      3. Wheels and casters
      4. The motor for the powered chair
      5. The steering mechanism for the powered chair
      6. The battery for the powered chair
      7. The track drive system for the Texas Tank
    7. Adding patterns
    8. The first design meeting
    9. The second pass
    10. The Builder pattern
    11. The Singleton pattern
    12. The Composite pattern
    13. The Bridge pattern
    14. The Command pattern
    15. Summary
    16. Questions
    17. Further reading
  14. Chapter 7: Nothing Left but the Typing – Implementing the Wheelchair Project
    1. The crack of noon
    2. Setting up the project
      1. Wheelchair components
      2. Finishing the wheelchair base classes
    3. Finishing up the composite
    4. Implementing the Builder pattern
      1. Another refactor
      2. Adding concrete component classes
      3. Wrapping up the Builder pattern
    5. Adding the Singleton pattern
    6. Painting the chairs with the Bridge pattern
    7. Summary
    8. Questions
    9. Further reading
  15. Chapter 8: Now You Know Some Patterns, What Next?
    1. Patterns we didn’t discuss
      1. Prototype
      2. Adapter
      3. Flyweight
      4. Chain of Responsibility
      5. Proxy
      6. Interpreter
      7. Mediator
      8. Memento
      9. State
      10. Template Method
      11. Visitor
    2. Patterns beyond the realm of OOP
      1. Software architecture patterns
      2. Data access patterns
    3. Creating your own patterns
      1. Name and classification
      2. The problem description
      3. The solution description
      4. Consequences of using the pattern
    4. Not everybody likes patterns
    5. Summary
    6. Sundance Square – Fort Worth, Texas
    7. Further reading
  16. Appendix 1: A Brief Review of OOP Principles in C#
    1. Technical requirements
    2. A quick background of C#
      1. C# is a general-purpose language
      2. C# is purely and fully object-oriented
      3. C# uses a static, strong type system
      4. C# has automatic bounds checking and detection for uninitialized variables
      5. C# supports automated garbage collection
      6. C# code is highly portable
    3. Language mechanics in C#
      1. Variables in C#
      2. Classes
    4. Encapsulation
      1. C# auto-implemented properties
      2. Accessor logic with backing variables
    5. Inheritance
    6. Interfaces
      1. Defining interfaces
      2. Implementing interfaces
    7. IDEs for C# development
      1. Visual Studio
      2. VS Code
      3. Rider
    8. Summary
    9. Further reading
  17. Appendix 2: A Primer on the Unified Modeling Language (UML)
    1. Technical requirements
    2. The structure of a class diagram
      1. Classes
      2. Interfaces
      3. Enumerations
      4. Packages
    3. Connectors
      1. Inheritance
      2. Interface realization
      3. Composition
      4. Association
      5. Aggregation
      6. Directed association
      7. Dependency
    4. Notes
    5. Best practices
      1. Less is more – don’t try to put everything in one big diagram
      2. Don’t cross the lines
      3. The most direct path for lines leads to a mess
      4. Parents go above children
      5. Keep your diagrams neat
    6. Summary
    7. Further reading
  18. Index
    1. Why subscribe?
  19. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: Real-World Implementation of C# Design Patterns
  • Author(s): Bruce M. Van Horn Ii
  • Release date: October 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781803242736