This project demonstrates the implementation of two popular Object-Oriented Design Patterns in Java:
- Singleton Pattern
- Factory Pattern
The application showcases how these design patterns help create clean, maintainable, reusable, and scalable Java applications.
The project contains two independent implementations of design patterns:
The Singleton Pattern ensures that only one instance of a class is created throughout the application's lifecycle. It provides a global point of access to that instance.
The Factory Pattern provides an interface for creating objects without exposing the object creation logic to the client. The client requests an object from the factory instead of creating it directly.
- Java
- Eclipse / Spring Tool Suite (STS)
- Object-Oriented Programming (OOP)
DesignPatternsDemo
│
├── src
│ └── com.example.designpatterns
│ ├── Main.java
│ ├── Singleton.java
│ ├── Shape.java
│ ├── Circle.java
│ ├── Rectangle.java
│ └── ShapeFactory.java
│
├── README.md
└── .gitignore
- Private constructor
- Static instance variable
- Public static
getInstance()method - Ensures only one object is created
- Uses an interface (
Shape) - Implements multiple classes (
Circle,Rectangle) - Uses
ShapeFactoryto create objects - Promotes loose coupling and code reusability
- Open the project in Eclipse or STS.
- Navigate to:
src → com.example.designpatterns - Open
Main.java. - Right-click → Run As → Java Application.
- View the output in the Console.
===== Singleton Pattern =====
Singleton object created.
Hello from Singleton Pattern!
Only one Singleton object exists.
===== Factory Pattern =====
Drawing Circle
Drawing Rectangle
- Classes and Objects
- Interfaces
- Encapsulation
- Abstraction
- Polymorphism
- Singleton Design Pattern
- Factory Design Pattern
- Object Creation
- Code Reusability
- Demonstrates real-world Java design patterns.
- Improves code maintainability.
- Promotes loose coupling.
- Easy to understand and extend.
- Beginner-friendly implementation.
Vedika Pawade
Computer Science & Engineering Student
This project is created for educational and learning purposes.