From the course: Design Patterns: Creational

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Control how objects are created

Control how objects are created

From the course: Design Patterns: Creational

Start my 1-month free trial

Control how objects are created

- [Narrator] The Singleton Design Pattern is one of those patterns whose implementation like prototype is going to depend a little on which language you're working with, because each language will have different ways to handle class variables and class methods, thread safety and so on. That said, the general idea of Singleton is useful because now and then we do find ourselves in situations where we need to ensure there really is one and only one instance of a class. This allows us to control how objects are created, accessed and used in a system. Because the Singleton class encapsulates the instance of the class, the Singleton class can be designed to allow access to whatever resource or data the Singleton is managing via a restricted API that allows only certain operations. If you need to change how a resource is used, you change only the code in the Singleton, so you've encapsulated the behavior associated with that…

Contents