Hands-On Design Patterns with C# and .NET Core
Write clean and maintainable code by using reusable solutions to common software design problems
Gaurav Aroraa
Jeffrey Chilberto
BIRMINGHAM - MUMBAI
Hands-On Design Patterns with C# and .NET Core
Copyright 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Commissioning Editor: Richa Tripathi
Acquisition Editor: Chaitanya Nair
Content Development Editor: Akshita Billava
Senior Editor: Afshaan Khan
Technical Editor: Neha Pande
Copy Editor: Safis Editing
Language Support Editor : Storm Mann
Project Coordinator: Carol Lewis
Proofreader: Safis Editing
Indexer: Tejal Daruwale Soni
Production Designer: Alishon Mendonsa
First published: July 2019
Production reference: 1040719
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78913-364-6
www.packtpub.com
To my mother, Late Smt. Santosh, and to the memory of my father, the late Sh. Ramkrishan, for
their sacrifices and for exemplifying the power of determination. To my youngest sister, the late
Baby Kanchan, for her love and always being my lucky charm.
Gaurav Aroraa
My parents, Francis and Joyce, who tirelessly put their children first, with love, support, and kindness. To my brothers: Jack, for inspiring me to persevere through challenges, and Mike, for reminding me to stop and take the time to enjoy life.
Jeffrey Chilberto
Packt.com
Subscribe to our online digital library for full access to over 7,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Fully searchable for easy access to vital information
Copy and paste, print, and bookmark content
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at customercare@packtpub.com for more details.
At www.packt.com , you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks.
Foreword
When designing good software, engineers naturally gravitate toward solutions that avoid duplication. We are naturally DRYDon't Repeat Yourselfoften without thinking about it! Developers naturally compartmentalize functionality, create reusable methods, and make helpful classes.
However, many software design patterns have been created over the years. These are useful, general, and reusable solutions to problems you'll see every day. There are more and more developers who are self-taught or who didn't go through a classical software engineer or computer science course at university, and everyone should enjoy the benefits of decades of development of these great design patterns.
Gaurav and Jeffrey have assembled the best and most common patterns and applied them to the open source world of .NET Core and C#. You'll start with OOP, classes, and objects and move your way on to inheritance, encapsulation, and polymorphism. They've covered design principles such as DRY, KISS, and SOLID (these will all make sense very soon!) and applied them to classic patterns that will help you make clear, crisp, and rock-solid (pun intended!) software.
This book is filled with real code that clearly illustrates how to apply all this knowledge to your .NET Core and C# software today. You'll learn how to adopt the Builder pattern, Decorator pattern, Factory pattern, Visitor pattern, and Strategy pattern, and so much more.
These techniques will then be applied to a simple app, then to a web application, and then to more complex problems involving concurrency and parallelism! You'll then apply patterns at a more macro level using solution patterns that will help you move your projects to the cloud in a scalable and maintainable way.
I hope you appreciate this book as much as I did. And I hope you enjoy working with .NET Core and have as much fun as we did making it!
Scott Hanselman
Partner Program ManagerMicrosoft
.NET and Open Source Community
This book is a blessing for every developer looking to raise their development skills to the next level, but more importantly, to build scalable, maintainable, and robust solutions. Most industry standards and best practices are covered, using straight-to-the-point examples.
Beyond development design patterns, the book also tackles underlying architecture principles and some key cloud aspects, such as security and scaling.
As a solution architect, I am involved day in day out in, designing end-to-end solutions, from the development aspects to the underlying infrastructure and security bits, and yet I am impressed by the quality contents and the broad scope of this book. It contains a very comprehensive list of patterns that everyone should take a look at when considering the development and deployment of new workloads.
This in-depth immersion into the Object-oriented programming (OOP) and .NET Core worlds is profitable to anyone interested in writing best-in-class applications.
Stephane Eyskens
Azure MVP
Contributors
About the authors
GauravAroraa has an M.Phil in computer science. He is a former Microsoft MVP, Alibaba Cloud MVP, certified as a Scrum trainer/coach, a lifetime member of
Next page