From the course: Java EE: Design Patterns and Architecture
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
The Singleton design pattern
From the course: Java EE: Design Patterns and Architecture
The Singleton design pattern
- [Instructor] What is the motivation for the singleton pattern? Well it's about having a single instance of an object in the JVM that is only ever instantiated once within the life cycle of the application. It provides a global point of access to the object, which once created is not destroyed until the application terminates. But why do you need this single object in the first place? The reason is that heavy weight objects, such as connection pools and loggers, are expensive to construct, and therefore you would not want to create them every time you require a connection, or you want to output a message to a log. These objects should be created only once by the singleton, and they're made available to the entire application for the life of the application. If you ever implemented the singleton pattern in Java SE, or in other language, you will know that it's implementation is really quite non-trivial. You have to start with some pretty unnatural constructs, like double-check…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Classic design patterns revisited1m 51s
-
(Locked)
The Singleton design pattern2m 6s
-
(Locked)
Implement a Singleton pool manager5m 58s
-
(Locked)
Advanced Singleton pattern3m 58s
-
(Locked)
Singleton pattern concurrency5m 4s
-
(Locked)
The Facade design pattern2m 10s
-
(Locked)
Implement the Facade pattern4m 54s
-
(Locked)
Advanced Facade services4m 59s
-
(Locked)
The Observer design pattern3m 14s
-
(Locked)
Implement Observer pattern8m 3s
-
(Locked)
Observer priority and qualifiers7m 28s
-
(Locked)
Asynchronous observer3m 54s
-
(Locked)
The Decorator design pattern2m 16s
-
(Locked)
Implement the Decorator pattern8m 39s
-
-
-
-
-
-
-
-
-