A comprehensive collection of software design pattern implementations in TypeScript and other languages.
This repository contains practical implementations of common software design patterns, helping developers understand how to apply these patterns in real-world scenarios. Each pattern is thoroughly documented with examples and use cases.
- Abstract Factory
- Builder
- Factory Method
- Prototype
- Singleton
- Adapter
- Bridge
- Composite
- Decorator
- Facade
- Flyweight
- Proxy
- Chain of Responsibility
- Command
- Interpreter
- Iterator
- Mediator
- Memento
- Observer
- State
- Strategy
- Template Method
- Visitor
.
├── src/
│ ├── builder/
│ │ ├── ts/ # TypeScript implementation
│ │ │ └── variant1/
│ │ │ ├── index.ts # Source code
│ │ │ └── ... # Other files
│ │ └── python/ # Python implementation
│ │ ├── variant1/
│ │ │ ├── main.py # Source code
│ │ │ └── ... # Other files
│ │ └── variant2/
│ │ ├── main.py # Source code
│ │ └── ... # Other files
│ ├── ... # Other patterns
│
└── README.md
- Node.js (v14 or later)
- TypeScript (v4 or later)
Clone the repository:
git clone https://github.com/yourusername/design-patterns.git
cd design-patternsInstall dependencies:
npm installTo run a specific pattern example:
# For TypeScript examples
npx ts-node src/[pattern]/ts/[variant]/index.ts
# Example for Builder pattern
npx ts-node src/builder/ts/functional/index.tsThe Builder pattern allows for the step-by-step construction of complex objects using the correct sequence of actions. The construction is controlled by a director object that only needs to know the type of object it is to create.
Our implementation features:
- Abstract
Housebase class - Concrete house types (Modern, Traditional, Eco-Friendly)
- Builder interface and concrete builders
- Director class to create pre-configured objects
// Create builders
const modernBuilder = new ModernHouseBuilder();
const traditionalBuilder = new TraditionalHouseBuilder();
const ecoBuilder = new EcoFriendlyHouseBuilder();
// Use the director
const director = new HouseDirector();
const modernHouse = director.constructFullFeaturedModernHouse(
new ModernHouseBuilder(),
);
const traditionalHouse = director.constructFullFeaturedTraditionalHouse(
new TraditionalHouseBuilder(),
);
// Or configure manually
const customEcoHouse = ecoBuilder
.setFoundation('Recycled Concrete')
.setStructure('Sustainable Timber')
.setRoof('Green Roof')
.addSolarPanels()
.build();
// Display house details
modernHouse.describe();
traditionalHouse.describe();
customEcoHouse.describe();Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-pattern) - Commit your changes (
git commit -m 'Add some amazing pattern') - Push to the branch (
git push origin feature/amazing-pattern) - Open a Pull Request
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.
For any inquiries or suggestions, please contact me
- "Design Patterns: Elements of Reusable Object-Oriented Software" by Gang of Four
- Modern TypeScript best practices