Intermediate

C-Sharp Design Patterns Singleton

This course covers the Singleton pattern, one of the most well-known but also most misused design patterns.

Design patterns are like individual tools that one can add to their toolbox as a software developer. They don't take long to introduce, but can require a lot of practice to master.

By the end of this course, you will be able to recognize situations where the Singleton pattern makes sense, and apply it—or an alternative—with confidence.

A Singleton is a class designed to allow the creation of only a single instance of itself. The class itself is responsible for enforcing this design constraint.

Sign in to read this course

A free account unlocks all 514 courses. 20 are readable without one.

What's inside

19 sections
  1. 1 Table of Contents
  2. 2 Course Overview
  3. 3 Introduction to the Singleton pattern
  4. 4 Structure and characteristics of the Singleton
  5. 5 Naive implementation — v1 (Naive Singleton)
  6. 6 Implementation with lock — v2 (Thread Safe Singleton with lock)
  7. 7 Double Checked Locking — v3 (Best Lock)
  8. 8 Analysis of lock approaches
  9. 9 Static and Singleton Constructors
  10. 10 Singleton with static initialization — v4 (Less Lazy)
  11. 11 Singleton with nested class — v5 (Nested Lazy)
  12. 12 Analysis of approaches by static constructor
  13. 13 Singleton with Lazy<T> — v6 (Recommended approach)
  14. 14 Is the Singleton an anti pattern?
  15. 15 Singleton vs. Static classes
  16. 16 Using IoC/DI Containers
  17. 17 Testing Considerations
  18. 18 Key Takeaways
  19. 19 Resources and references

Interested in this course?

Contact us to book it or get a custom training plan for your team.