A comprehensive collection of design patterns implemented in Java, organized according to IntelliJ IDEA and Maven standards.
This project follows the standard Maven directory structure:
src/
├── main/
│ └── java/
│ └── com/
│ └── designpatterns/
│ ├── creational/
│ │ ├── abstractfactory/
│ │ ├── builder/
│ │ ├── factory/
│ │ ├── prototype/
│ │ └── singleton/
│ └── structural/
│ └── facade/
Package: com.designpatterns.creational.abstractfactory
Creates families of related objects without specifying their concrete classes.
Classes:
FurnitureFactory- Abstract factory interfaceModernFurnitureFactory- Concrete factory for modern furnitureVictorianFurnitureFactory- Concrete factory for Victorian furnitureChair- Abstract product interfaceTable- Abstract product interfaceModernChair,ModernTable- Concrete modern productsVictorianChair,VictorianTable- Concrete Victorian productsFactory- Main class demonstrating the pattern
Package: com.designpatterns.creational.builder
Constructs complex objects step by step.
Classes:
Pizza- Product class with inner BuilderBuilder- Main class demonstrating the pattern
Package: com.designpatterns.creational.factory
Creates objects without specifying their exact classes.
Classes:
PizzaFactory- Abstract factory interfaceMargheritaPizzaFactory- Concrete factory for Margherita pizzaVeggiePizzaFactory- Concrete factory for veggie pizzaPizza- Abstract product interfaceMargheritaPizza,VeggiePizza- Concrete productsPizzaStore- Main class demonstrating the pattern
Package: com.designpatterns.creational.prototype
Creates new objects by cloning an existing object.
Classes:
Character- Prototype interfaceOrc- Concrete prototype implementation
Package: com.designpatterns.creational.singleton
Ensures a class has only one instance and provides global access to it.
Classes:
CacheManager- Thread-safe singleton with synchronized methodDatabaseSingleton- Singleton for database connection management
Package: com.designpatterns.structural.facade
Provides a simplified interface to a complex subsystem.
Classes:
Restraunt- Facade classOrder- Data class for ordersOrderService- Subsystem class for order managementKitchenService- Subsystem class for kitchen operations
- Java 11 or higher
- Maven 3.6 or higher
- IntelliJ IDEA (recommended)
- Clone the repository
- Open the project in IntelliJ IDEA
- Import as Maven project
- Build the project using Maven:
mvn clean compile
Each pattern includes a main class that demonstrates its usage. You can run these directly from IntelliJ IDEA or using Maven:
# Run Abstract Factory example
mvn exec:java -Dexec.mainClass="com.designpatterns.creational.abstractfactory.Factory"
# Run Builder example
mvn exec:java -Dexec.mainClass="com.designpatterns.creational.builder.Builder"
# Run Factory example
mvn exec:java -Dexec.mainClass="com.designpatterns.creational.factory.PizzaStore"The project uses Maven for dependency management and build configuration. Key dependencies:
- MySQL Connector (for DatabaseSingleton example)
- Source folders are properly configured in
pom.xml - Package structure follows Java conventions
- All classes have proper package declarations
When adding new patterns:
- Follow the existing package structure
- Use appropriate package names (e.g.,
com.designpatterns.behavioral.commandfor behavioral patterns) - Include a main class demonstrating the pattern
- Update this README with pattern descriptions
This project organizes patterns into three main categories:
- Creational Patterns - Deal with object creation mechanisms
- Structural Patterns - Deal with object composition and relationships
- Behavioral Patterns - Deal with communication between objects (to be added)
- Each pattern is implemented in its own package
- All classes have proper package declarations
- Examples include practical use cases
- Code follows Java naming conventions
- Thread safety is considered where applicable