1. Learn
  2. /
  3. Courses
  4. /
  5. Optimizing Code in Java

Connected

Exercise

Implementing the Singleton pattern

Your application needs to manage logging configurations across multiple components. Each component currently creates its own LogManager, causing configuration inconsistencies. You need to finish the implementation of the singleton pattern to ensure all components share the same logging configuration.

Instructions

100 XP
  • Add a static variable called instance of type LogManager.
  • Make the constructor accessible only from within the class.
  • Only create a LogManager instance if is it currently null.