Design Patterns in C# and .NET
4.4 (5,849 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
36,746 students enrolled

Design Patterns in C# and .NET

Discover the modern implementation of design patterns with C# and .NET
Bestseller
4.4 (5,849 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
36,746 students enrolled
Created by Dmitri Nesteruk
Last updated 5/2020
English
English [Auto], French [Auto], 6 more
  • German [Auto]
  • Indonesian [Auto]
  • Italian [Auto]
  • Polish [Auto]
  • Portuguese [Auto]
  • Spanish [Auto]
Current price: $64.99 Original price: $99.99 Discount: 35% off
7 minutes left at this price!
30-Day Money-Back Guarantee
This course includes
  • 18 hours on-demand video
  • 1 article
  • 111 downloadable resources
  • 23 coding exercises
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
Training 5 or more people?

Get your team access to 4,000+ top Udemy courses anytime, anywhere.

Try Udemy for Business
What you'll learn
  • Recognize and apply design patterns
  • Refactor existing designs to use design patterns
  • Reason about applicability and usability of design patterns
Course content
Expand all 159 lectures 17:57:18
+ The SOLID Design Principles
7 lectures 55:55

What are SOLID principles, where do they come from and why do we care?

Overview
01:16

A look at the Single Responsibility Principle, which states that a class should only have one reason to change. Also tied to the concept of Separation of Concerns which is basically stating the same thing.

Single Responsibility Principle
07:29

A discussion of the Open-Closed Principle, which states that classes should be open for extension, but closed for modification. In other words, you should extend functionality using interfaces and inheritance rather than jumping back into already-written/tested code and adding to it or changing it.

Preview 17:24

The Liskov Substitution Principle states that subtypes should be substitutable for their base types.

Liskov Substitution Principle
06:37

The Interface Segregation Principle is simple: don't throw everything in the kitchen sink into an interface because then all its users will have to implement things they do not need. Instead, split the interface into several smaller ones.

Interface Segregation Principle
06:33

Not to be confused with dependency injection, dependency inversion specifies that high-level modules should not depend on low-level ones; both should depend on abstractions. Confusing, huh?

Dependency Inversion Principle
11:11

A summary of the things we've learned in this section of the course.

Summary
05:25
+ Builder
9 lectures 54:19

A brief note about the three categories of design patterns: creational, structural and behavioral.

Gamma Categorization
03:36

A discussion of the Builder design pattern and what it's used for.

Overview
01:43

A look at why you'd want to have a builder in the first place.

Life Without Builder
03:34

We implement a simple builder for constructing trees of HTML elements.

Builder
09:06

We make the builder fluent by returning this from builder methods.

Fluent Builder
01:16

Inheriting fluent interfaces is not easy because this cannot be returned in a virtual way. But we can make it work using recursive generics.

Fluent Builder Inheritance with Recursive Generics
12:37

We can extend a builder without breaking OCP using a functional approach and extension methods.

Functional Builder
10:19

We look at a more complicated builder facade that exposes several sub-builders (builder facets) for building up parts of an object in a fluent manner.

Preview 11:11
Builder Coding Exercise
1 question

A summary of the things we've learned about the Builder pattern.

Summary
00:57
+ Factories
9 lectures 48:02

A discussion of the general concept of factories and the two design patterns: Factory Method and Abstract Factory.

Overview
02:22

A scenario where having a factory interface actually makes sense.

Point Example
04:38

Implementing a factory method is easy, and you can turn a constructor into a factory method using ReSharper.

Factory Method
05:03

We want to perform async initialization, but constructors cannot be marked async. Factories to the rescue!

Asynchronous Factory Method
05:01

When you want all the factory methods in a separate class.

Factory
02:59

An external factory needs the created object's constructor to be public. But what if you want it to be private? The solution is simple: stick a factory into the class whose instances it creates!

Inner Factory
05:41

Sometimes, you want abstract factories with abstract objects; we support DIP but break OCP in the process.

Abstract Factory
11:21

Can we fix an OCP violation without introducing an IoC container? Seems we can.

Abstract Factory and OCP
09:52
Factory Coding Exercise
1 question

A summary of the things we've learned in this module.

Summary
01:05
+ Prototype
6 lectures 26:18

A discussion of the Prototype factory (not to be confused with a rather good game of the same name) and what it's used for.

Overview
01:59

The .net Framework comes with an ICloneable interface but its use is not recommended. Why not?

ICloneable is Bad
07:37

Another suspect approach from the land of C++. While it avoids the confusion of ICloneable, it's not clear-cut either. Plus, we still have to do things recursively, which is tiring.

Copy Constructors
03:55

Let's be clear about what we're doing.

Explicit Deep Copy Interface
02:34

How to make a copy of the entire object graph without writing any copy-specific code? Easy, just serialize and deserialize!

Copy Through Serialization
09:05
Prototype Coding Exercise
1 question

A summary of all the things we've learned about the prototype pattern.

Summary
01:08
+ Singleton
8 lectures 50:35

Ahh, the much maligned Singleton? Is it really that evil? Let's find out...

Overview
02:43

Avoiding all the philosophical nonsense surrounding double-checked locking (it’s not thread-safe) and implementations involving inner static classes (with an empty static constructor to avoid beforefieldinit), we simply look at a safe .net 4-like way of making a lazy, thread-safe singleton.

Singleton Implementation
08:40

The singleton works fine, so what's the problem? Turns out, hard reference to a type means we cannot fake it in our tests. Oops!

Testability Issues
07:22

The only socially acceptable way of using a singleton is with a DI framework.
Typically, marking a component as a singleton is trivial. Check out my Dependency
Injection course! (link below)

Singleton in Dependency Injection
08:58

A variation on a Singleton pattern, the Monostate lets the client instantiate as many copies of the singleton class as they want, but all those copies refer to the same static data. Is this a good idea? Let’s find out!

Monostate
03:46

An alternative that completely skirts the issue of thread safety.

Per-Thread Singleton
04:25

A very common and simple design pattern.

Ambient Context
12:26
Singleton Coding Exercise
1 question

A summary of all that we've learned about the Singleton. As you can see, it's not really that evil provided it can be substituted by a different type (polymorphism). Also, lifetime management is best left to a specialized system (i.e. a DI container).

Summary
02:15
+ Adapter
6 lectures 52:50

A look at the Adapter design pattern.

Overview
02:36

We are going to build a simple adapter for the rending of vector data where only a raster renderer is available. 

Vector/Raster Demo
08:35

An adapter can generate a large number of temporary objects. Caching helps us avoid doing extra work more than once.

Adapter Caching
06:04

Unlike C++, C# does not allow us to use literal values (numbers, strings) as generic arguments. Generic Value Adapter is a pattern that helps us deal with this. This lecture also uses the Factory Method design pattern and recursive generics.

Preview 25:18

Let's take a look at how Autofac supports the creation of adapters. For more info on Dependency Injection, see my Autofac course!

Adapter in Dependency Injection
09:07
Adapter Coding Exercise
1 question

A summary of all the things we've learned about the Adapter pattern.

Summary
01:10
+ Bridge
3 lectures 14:12

A discussion of the Bridge pattern and what it's used for.

Overview
02:50

A simple illustration of how to build a bridge.

Bridge
09:49
Bridge Coding Exercise
1 question

A summary of all the important things we've learned in this section of the course.

Summary
01:33
+ Composite
5 lectures 24:35

A discussion of what the Composite pattern is for and how it's used.

Overview
01:53

Let's implement the Composite pattern by considering individual geometric shapes as well as grouping of shapes.

Geometric Shapes
07:33

Let's apply the Composite pattern to the implementation of simple neural networks (individual neurons and layers of neurons).

Neural Networks
08:00

A look back at our OCP demo, where we use the Composite pattern to introduce a base class useful for making combinators.

Composite Specification
05:58
Composite Coding Exercise
1 question

A summary of all the things we've learned about the Composite design pattern.

Summary
01:11
+ Decorator
9 lectures 57:11

A look at the Decorator design pattern.

Overview
02:34

StringBuilder is unfortunately sealed. Let's see how we can have its de facto inheritor as a Decorator.

Custom String Builder
06:19

Here we build a pattern which is both a decorator (over a StringBuilder) and an adapter (adapting string's operator support).

Adapter-Decorator
06:33

When you implement pseudo-multiple inheritance using interfaces, you quite often end up implementing the Decorator pattern.

Multiple Inheritance with Interfaces
08:40

C#8 introduces default interface members. Does this change the MI situation? Not really.

Multiple Inheritance with Default Interface Members
07:44

A look at how to make decorators-of-decorators.

Dynamic Decorator Composition
07:39

Can decorators be composed as nested generic type arguments? They can, but things aren't as rosy in .NET as they are in C++.

Static Decorator Composition
09:30

Let's take a look at how Autofac supports decorators. For more info on Dependency Injection, see my Autofac course!

Decorator in Dependency Injection
06:10
Decorator Coding Exercise
1 question

A summary of all the things we've learned about the Decorator design pattern.

Summary
02:02
Requirements
  • Good understanding of C#
  • Familiarity with latest C# features
  • Good understanding of object-oriented design principles
Description

Course Overview

This course provides a comprehensive overview of Design Patterns in C# and .NET from a practical perspective. This course in particular covers patterns with the use of:

  • The latest versions of C# and the .NET framework
  • Use of modern programming approaches: dependency injection, reactive programming and more
  • Use of modern developer tools such as ReSharper
  • Discussions of pattern variations and alternative approaches

This course provides an overview of all the Gang of Four (GoF) design patterns as outlined in their seminal book, together with modern-day variations, adjustments, discussions of intrinsic use of patterns in the language.

What are Design Patterns?

Design Patterns are reusable solutions to common programming problems. They were popularized with the 1994 book Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, John Vlissides, Ralph Johnson and Richard Helm (who are commonly known as a Gang of Four, hence the GoF acronym).

The original book was written using C++ and Smalltalk as examples, but since then, design patterns have been adapted to every programming language imaginable: C#, Java, PHP and even programming languages that aren't strictly object-oriented, such as JavaScript.

The appeal of design patterns is immortal: we see them in libraries, some of them are intrinsic in programming languages, and you probably use them on a daily basis even if you don't realize they are there.

What Patterns Does This Course Cover?

This course covers all the GoF design patterns. In fact, here's the full list of what is covered:

  • SOLID Design Principles: Single Responsibility Principle, Open-Closed Principle, Liskov Substitution Principle, Interface Segregation Principle and Dependency Inversion Principle
  • Creational Design Patterns: Builder, Factories (Factory Method and Abstract Factory), Prototype and Singleton
  • Structrural Design Patterns: Adapter, Bridge, Composite, Decorator, Façade, Flyweight and Proxy
  • Behavioral Design Patterns: Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Null Object, Observer, State, Strategy, Template Method and Visitor

Who Is the Course For?

This course is for .NET/C# developers who want to see not just textbook examples of design patterns, but also the different variations and tricks that can be applied to implement design patterns in a modern way. For example, the introduction of the DLR allows us to use an ImpromptuObject, so that our DynamicObject exposes any interface we desire. This allows for dynamic programming, and many design patterns are presented in terms of their static and DLR-based variations.

Presentation Style

This course is presented as a (very large) series of live demonstrations being done in Microsoft Visual Studio. Most demos are single-file, so you can download the file attached to the lesson and run it in Visual Studio, Visual Studio Code, Rider or another IDE of your choice.

This course does not use UML class diagrams; all of demos are live coding. I use Visual Studio, various NuGet packages, R# unit test runner and even dotMemoryUnit.


Who this course is for:
  • Beginner and experienced developers
  • Anyone interested in design patterns