This repository contains sample source code implementations of various design patterns.
The purpose is to provide a clean and practical reference for developers who want to understand how design patterns can be applied in real projects.
All examples are organized by categories → design patterns → programming languages.
.
├── Creational/ # Khởi tạo (Creational Patterns)
│ ├── Singleton/
│ │ ├── Java/
│ │ ├── Php/
│ │ └── Python/
│ ├── FactoryMethod/
│ └── AbstractFactory/
│
├── Structural/ # Cấu trúc (Structural Patterns)
│ ├── Adapter/
│ ├── Decorator/
│ └── Proxy/
│
└── Behavioral/ # Hành vi (Behavioral Patterns)
├── Observer/
├── Strategy/
└── Command/
Pattern | Link |
---|---|
Singleton | View Code |
Factory Method | View Code |
Abstract Factory | View Code |
Builder | View Code |
Prototype | View Code |
Pattern | Link |
---|---|
Adapter | View Code |
Bridge | View Code |
Composite | View Code |
Decorator | View Code |
Facade | View Code |
Flyweight | View Code |
Proxy | View Code |
Pattern | Link |
---|---|
Chain of Responsibility | View Code |
Command | View Code |
Iterator | View Code |
Mediator | View Code |
Memento | View Code |
Observer | View Code |
State | View Code |
Strategy | View Code |
Template Method | View Code |
Visitor | View Code |
Each folder contains subfolders for supported programming languages (e.g.,
Java
,Php
, ...).
- Navigate to the pattern folder you want to study.
- Choose the programming language (e.g.,
Java
,Php
). - Open the source code files.
- Compile and run them locally.
Examples:
Java:
# Structure demo (basic implementations)
cd Creational/Singleton/Java/Structure
javac *.java
java Main
# Example demo (real-world example)
cd ../Example
javac ../Structure/*.java *.java
java Main
PHP:
# Structure demo (basic implementations)
cd Creational/Singleton/Php/Structure
php Main.php
# Example demo (real-world example)
cd ../Example
php Main.php
Concepts are based on Refactoring.Guru – Design Patterns. This repository only provides source code samples, not detailed explanations.
You are welcome to contribute by:
- Adding new design pattern implementations
- Supporting more programming languages
- Improving code quality
Released under the MIT License. You can freely use, modify, and share the code with attribution.