Skip to content

This repository contains sample source code implementations of various design patterns. Each example is structured to demonstrate the core concepts, usage scenarios, and best practices for applying the pattern in real-world software development.

License

Notifications You must be signed in to change notification settings

daotanphat/design-patterns

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Design Patterns Samples

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 categoriesdesign patternsprogramming languages.


📂 Repository Structure

.
├── 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/

📖 Patterns Included

Creational

Pattern Link
Singleton View Code
Factory Method View Code
Abstract Factory View Code
Builder View Code
Prototype View Code

Structural

Pattern Link
Adapter View Code
Bridge View Code
Composite View Code
Decorator View Code
Facade View Code
Flyweight View Code
Proxy View Code

Behavioral

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


🚀 Usage

  1. Navigate to the pattern folder you want to study.
  2. Choose the programming language (e.g., Java, Php).
  3. Open the source code files.
  4. 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

📚 Reference

Concepts are based on Refactoring.Guru – Design Patterns. This repository only provides source code samples, not detailed explanations.


🤝 Contribution

You are welcome to contribute by:

  • Adding new design pattern implementations
  • Supporting more programming languages
  • Improving code quality

📜 License

Released under the MIT License. You can freely use, modify, and share the code with attribution.

About

This repository contains sample source code implementations of various design patterns. Each example is structured to demonstrate the core concepts, usage scenarios, and best practices for applying the pattern in real-world software development.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 57.0%
  • Java 43.0%