We may earn an affiliate commission when you visit our partners.
Course image
Dmitri Nesteruk

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
Read more

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.

Enroll now

Here's a deal for you

We found an offer that may be relevant to this course.
Save money when you learn. All coupon codes, vouchers, and discounts are applied automatically unless otherwise noted.

What's inside

Learning objectives

  • Recognize and apply design patterns
  • Refactor existing designs to use design patterns
  • Reason about applicability and usability of design patterns

Syllabus

A taste of things to come...

Understand the SOLID design principles

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

Read more

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.

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.

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

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.

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?

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

Learn to use Builder, a pattern for creating composite objects

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

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

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

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

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

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

How do you enforce that builder methods are called in a specific order?

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

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.

Builder Coding Exercise

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

Effectively use the Factory Method and Abstract Factory patterns

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

A scenario where having a factory interface actually makes sense.

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

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

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

An additional benefit of factories is they can keep weak references to objects they create or even, with one level of indirection, to replace those objects entirely.

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!

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

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

Factory Coding Exercise

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

Learn to use Prototype, a pattern that reuses already-constructed objects

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.

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

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.

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

How would you succinctly implement inheritance when deep copying is concerned?

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

Prototype Coding Exercise

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

Learn to use (or avoid using) the much maligned Singleton pattern

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

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.

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!

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)

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!

An alternative that completely skirts the issue of thread safety.

A very common and simple design pattern.

Singleton Coding Exercise

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).

Learn to use the Adapter design pattern

A look at the Adapter design pattern.

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

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

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.

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

Adapter Coding Exercise

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

Learn to use the Bridge design pattern

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

A simple illustration of how to build a bridge.

Bridge Coding Exercise

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

Learn to use the Composite design pattern

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

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

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

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

Composite Coding Exercise

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

Learn to use the Decorator design pattern

A look at the Decorator design pattern.

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

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

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

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

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

How can you handle a decorator being applied more than once?

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

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

Decorator Coding Exercise

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

Learn to use the Façade design pattern

A look at the Facade design pattern. Also an explanation of that weird letter C.

Instead of building a clinical example, let's take a look at a real-life Facade!

Facade Coding Exercise

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

Learn to use the Flyweight design pattern

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

So what if .NET does string interning? We can still find a scenario where string space optimization is possible.

Text formatting is a classic example of a Flyweight. Instead of keeping formatting flags for every single character in a line of text, let's implement ranges!

Flyweight Coding Exercise

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

Learn to use the Proxy design pattern

A look at the Proxy design pattern.

Let's implement a proxy which adds access control to the object.

One very common scenario is where developers replace ordinary properties with Property<T>-typed objects. Let's build out own implementation and discuss what it's for.

A proxy for a single value? Why would you need this?

Good to know

Know what's good
, what to watch for
, and possible dealbreakers
Provides an overview of all Gang of Four (GoF) patterns, including modern variations, adjustments, and discussions on the intrinsic use of patterns in the language
Covers all the GoF design patterns, including the 15 SOLID principles, Creational, Structrural, and Behavioral patterns
Provides live demonstrations and coding examples in Microsoft Visual Studio using various NuGet packages, R# unit test runner, and dotMemoryUnit
Emphasizes refactoring existing designs to use design patterns and reasoning about their applicability and usability
Taught by Dmitri Nesteruk, an experienced instructor with a strong reputation in software design patterns
Uses a very large series of live demonstrations, allowing for a more hands-on approach to learning

Save this course

Save Design Patterns in C# and .NET to your list so you can find it easily later:
Save

Reviews summary

Comprehensive design patterns course

According to students, this course is comprehensive and well-paced for those comfortable using Resharper
Thorough; covers many design patterns.
"Overall it was very good and comprehensive."
May be difficult for learners who opt out of using the Resharper tool.
"Overall it was very good and comprehensive."
"As a side note, I think that using Resharper to generate code does turn up the pace and makes it harder to keep up as a code-along for those who opt out of the tool, but I do understand the need to speed up an otherwise very extensive and time consuming course."

Activities

Be better prepared before your course. Deepen your understanding during and after it. Supplement your coursework and achieve mastery of the topics covered in Design Patterns in C# and .NET with these activities:
Review Strategy of Design Patterns
Work through some SOLID and GoF exercises to better prepare for what this course will talk about.
Browse courses on Design Patterns
Show steps
  • Read existing code examples and work through exercises found in other references
  • Check out these resources: https://refactoring.guru/design-patterns, https://www.dofactory.com/net/design-patterns and https://www.codeproject.com/Articles/514266/Design-Patterns-in-NET
Read Head First Design Patterns by Eric Freeman and Elisabeth Robson
Review some of the popular reference materials for design patterns.
Show steps
  • Read through the first few chapters to familiarize yourself with the basic design patterns concepts.
  • Work through the exercises and examples to reinforce your understanding.
Brush up on your C# and .NET skills
This will brush up on foundational skills to better prepare for this course.
Browse courses on C#
Show steps
  • Read through some tutorials on C# and .NET.
  • Work through some coding exercises.
Five other activities
Expand to see all activities and additional details
Show all eight activities
Watch video tutorials on design patterns
These will give you a great overview of design patterns and how to use them.
Browse courses on Design Patterns
Show steps
  • Search for video tutorials on design patterns on YouTube or other online platforms.
  • Watch the tutorials and take notes on the key concepts.
Practice writing code examples
Work through some coding examples to reinforce what you have learned.
Browse courses on Design Patterns
Show steps
  • Write code to implement the Singleton design pattern.
  • Write code to implement the Factory Method design pattern.
Write a blog post or article about a design pattern
Writing out your understanding in your own words will help deepen your understanding.
Browse courses on Design Patterns
Show steps
  • Choose a design pattern to write about.
  • Research the pattern and make sure you understand it thoroughly.
  • Write a blog post or article that explains the pattern in detail.
Participate in a coding competition that focuses on design patterns
Pitting yourself against other coders will help you to identify your strengths and weaknesses and practice working on real-world projects.
Browse courses on Design Patterns
Show steps
  • Find a coding competition that focuses on design patterns.
  • Practice your design pattern skills before the competition.
  • Participate in the competition and try your best to win.
Contribute to an open-source project that uses design patterns
Contributing to an open-source project is a great way to learn from experienced developers and get your code reviewed.
Browse courses on Design Patterns
Show steps
  • Find an open-source project that uses design patterns.
  • Read the project's documentation and code to understand how they use design patterns.
  • Contribute to the project by fixing bugs, adding features, or improving the code.

Career center

Learners who complete Design Patterns in C# and .NET will develop knowledge and skills that may be useful to these careers:
Software Designer
Software designers use their knowledge of software design principles and patterns to design software systems. Your understanding of the principles of software design, and especially the Design Patterns in C# and .NET, will be an asset in this role. Many software designers work at large tech companies designing new products and features. With enough experience, software designers may advance to become software architects or lead software engineers.
Solutions Architect
Solutions architects bridge the gap between business and IT. Your knowledge of design patterns would be invaluable for this role. This role will be responsible for the design of a software system, including design patterns and ensuring the solution meets the client's requirements. As with lead roles and management, this role will likely require a graduate degree and several years of experience.
Machine Learning Engineer
Machine learning engineers design, develop, and deploy machine learning models. They work with other members of the machine learning team to collect data, train models, and evaluate results. Familiarity with design patterns will help machine learning engineers to design and develop efficient and maintainable machine learning systems. This course will be particularly helpful to machine learning engineers who want to learn more about design patterns. It will help them to understand the trade-offs between different design patterns and make better decisions about the design of their machine learning systems.
Lead Software Engineer
Lead software engineers lead teams of software engineers. This will often involve leading the design and implementation of software. Your knowledge of design patterns will help you to ensure the software is designed, developed, and maintained to a high standard. Because this role includes team management and leadership responsibilities, it is typically a mid to senior-level position and may require a graduate degree, but it would still be helpful for earlier-career software engineers to get a foundation in design patterns.
Deep Learning Engineer
Deep learning engineers design, develop, and deploy deep learning models. They work with other members of the deep learning team to collect data, train models, and evaluate results. Familiarity with design patterns will help deep learning engineers to design and develop efficient and maintainable deep learning systems. This course will be particularly helpful to deep learning engineers who want to learn more about design patterns. It will help them to understand the trade-offs between different design patterns and make better decisions about the design of their deep learning systems.
Computer Vision Engineer
Computer vision engineers design, develop, and deploy computer vision systems. They work with other members of the computer vision team to collect data, train models, and evaluate results. Computer vision often depends on deep learning models. Familiarity with design patterns will help computer vision engineers to design and develop efficient and maintainable computer vision systems. This course will be particularly helpful to computer vision engineers who want to learn more about design patterns. It will help them to understand the trade-offs between different design patterns and make better decisions about the design of their computer vision systems.
Natural Language Processing Engineer
Natural language processing (NLP) engineers design, develop, and deploy NLP systems. They work with other members of the NLP team to collect data, train models, and evaluate results. NLP often depends on deep learning models. Familiarity with design patterns will help NLP engineers to design and develop efficient and maintainable NLP systems. This course will be particularly helpful to NLP engineers who want to learn more about design patterns. It will help them to understand the trade-offs between different design patterns and make better decisions about the design of their NLP systems.
Product Manager
Product managers are responsible for the planning, development, and marketing of software products. They work with other members of the product team to define the product vision and roadmap. Product managers with a solid understanding of software design can make better decisions about the features and functionality of their products. This course will be very helpful to product managers who want to learn more about design patterns. It will help them to understand the trade-offs between different design patterns and make better decisions about the design of their products.
Software Architect
Software architects combine elements of computer science and software engineering to design, develop, and oversee complex software systems. In this role, your expertise in the Design Patterns in C# and .NET course will be instrumental in making architectural decisions to ensure software meets its requirements. Given your background, you may excel in this role.
Project Manager
Project managers are responsible for planning, executing, and closing software development projects. They work with other members of the project team to ensure that the project is completed on time, within budget, and according to specifications. Project managers with a solid understanding of software design can make better decisions about the project plan, schedule, and budget. This course will be very helpful to project managers who want to learn more about design patterns. It will help them to understand the trade-offs between different design patterns and make better decisions about the design of their projects.
Consultant
Consultants work with clients to solve business problems. A common problem for clients is poor software design. A consultant with knowledge of design patterns can advise clients on how to improve their software design. This course will help you gain a deeper understanding of design patterns, which can increase your value as a consultant.
Software Developer
Software developers write and maintain code for software systems. They also work with other members of the software team to design and test software systems. Your skill in organizing and writing code in a clear and understandable way will benefit any team. This course may be useful to software developers who want to advance to a software designer or similar role, or who are interested in learning more about design patterns in the context of software development best practices.
Data Scientist
Data scientists use data to solve business problems. They use a variety of techniques, including machine learning, statistics, and data mining. A deep understanding of principles of data organization will help data scientists create and maintain data structures, which is required to do complex mathematical operations and modeling. This course will be very helpful to data scientists who want to learn more about design patterns. It will help them to understand how to design data structures to improve the performance of their algorithms.
Quality Assurance Analyst
Quality assurance (QA) analysts test software systems to ensure that they meet the requirements and are free of defects. Developing and testing software requires a deep understanding of the software development process, which this course may help to improve. The course may also be useful to learn more about the principles of testing and debugging software, topics that QA analysts must be familiar with.
Technical Writer
Technical writers create documentation for software systems. This documentation can include user manuals, technical specifications, and release notes. Familiarity with design patterns will help technical writers to understand the software systems they are documenting. This course can help technical writers learn about design patterns and how to write clear and concise documentation.

Reading list

We've selected 15 books that we think will supplement your learning. Use these to develop background knowledge, enrich your coursework, and gain a deeper understanding of the topics covered in Design Patterns in C# and .NET.
The original book on design patterns, this seminal work outlines all 23 of the classic design patterns. A must-read for anyone interested in design patterns.
A comprehensive guide to design patterns in C#, this book covers both the classic design patterns and modern variations. It valuable resource for C# developers who want to learn more about design patterns.
A classic work on algorithms, this book provides a comprehensive overview of the fundamental algorithms used in computer science. It valuable resource for developers of all levels who want to learn more about the foundations of computer science.
A monumental work on computer science, this book provides a comprehensive overview of the fundamental algorithms and data structures used in computer programming. It valuable resource for developers of all levels who want to learn more about the foundations of computer science.
A comprehensive guide to software construction, this book covers everything from requirements gathering to testing and deployment. It valuable resource for developers of all levels who want to learn more about the software development process.
A comprehensive guide to algorithms, data structures, and problem solving with C++, this book covers both the classic algorithms and modern variations. It valuable resource for C++ developers of all levels who want to learn more about algorithms, data structures, and problem solving.
A more accessible introduction to design patterns than the Gang of Four book, Head First Design Patterns uses humor and real-world examples to make learning about design patterns fun.
A classic work on software architecture, this book provides a comprehensive overview of the patterns used in enterprise applications. It valuable resource for architects and developers who want to build scalable and maintainable systems.
A classic work on domain-driven design, this book provides a comprehensive overview of the principles and practices of domain-driven design. It valuable resource for developers who want to build complex software systems that are maintainable and extensible.
A comprehensive guide to data structures and algorithms in Java, this book covers both the classic algorithms and modern variations. It valuable resource for Java developers of all levels who want to learn more about data structures and algorithms.
A classic work on software development management, this book provides insights into the human factors that affect software development. It valuable resource for managers and developers who want to build successful software teams.
A classic work on software engineering, this book provides insights into the challenges and complexities of software development. It valuable resource for architects and developers who want to build successful software systems.

Share

Help others find this course page by sharing it with your friends and followers:
Our mission

OpenCourser helps millions of learners each year. People visit us to learn workspace skills, ace their exams, and nurture their curiosity.

Our extensive catalog contains over 50,000 courses and twice as many books. Browse by search, by topic, or even by career interests. We'll match you to the right resources quickly.

Find this site helpful? Tell a friend about us.

Affiliate disclosure

We're supported by our community of learners. When you purchase or subscribe to courses and programs or purchase books, we may earn a commission from our partners.

Your purchases help us maintain our catalog and keep our servers humming without ads.

Thank you for supporting OpenCourser.

© 2016 - 2024 OpenCourser