This project includes five common creational design patterns implemented in Java.
Each program is simple and shows the main idea of the pattern with short comments.
File: SingletonDemo.java
Idea: Ensures only one object is created for the whole program.
Use case: Logging, configuration, or database connection managers.
Bonus: Also included a LazySingletonDemo.java version that creates the object only when needed.
File: FactoryMethodDemo.java
Idea: Lets us create objects without using new directly.
Use case: When you need different objects based on input (like Circle, Square, Rectangle).
File: BuilderDemo.java
Idea: Helps create complex objects step by step using method chaining.
Use case: When there are many optional fields (like building a computer with different parts).
File: PrototypeDemo.java
Idea: Creates a copy of an existing object instead of building from scratch.
Use case: When object creation is expensive and we can clone an existing one.
File: AbstractFactoryDemo.java
Idea: Creates related objects (like button and checkbox) that belong to the same theme.
Use case: UI frameworks that support multiple themes (light/dark).
Note: This version allows choosing the theme at runtime using user input.
File: LazySingletonDemo.java
Idea: Singleton that is created only when needed (lazy initialization).
Use case: For better memory management and thread safety.
- Java 17
- IntelliJ IDEA Community Edition
Siyasath Shasma
(Assignment for Creational Design Patterns)