Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Creational Design Patterns in Java

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.

1. Singleton Pattern

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.

2. Factory Method Pattern

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).

3. Builder Pattern

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).

4. Prototype Pattern

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.

5. Abstract Factory Pattern

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.

Bonus

File: LazySingletonDemo.java
Idea: Singleton that is created only when needed (lazy initialization).
Use case: For better memory management and thread safety.

Tools Used

  • Java 17
  • IntelliJ IDEA Community Edition

Author

Siyasath Shasma
(Assignment for Creational Design Patterns)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages