A comprehensive study repository for learning and implementing design patterns using TypeScript.
This project is a practical study of design patterns implemented in TypeScript. It serves as a reference guide and learning resource for understanding how different design patterns work and when to apply them in real-world scenarios.
- Node.js (v14 or higher)
- npm or yarn
- TypeScript knowledge
- Clone the repository:
git clone <repository-url>
cd design_patterns_ts_study
- Install dependencies:
npm install
- Run the project:
npx ts-node src/index.ts
├── src/
│ ├── index.ts # Main entry point
│ └── creational/ # Creational Design Patterns
│ ├── README.md
│ ├── interfaces/
│ │ └── UserSingleton.ts # Interface definitions
│ └── singleton/ # Singleton Pattern Implementation
│ ├── EXPLANATION.md # Detailed pattern explanation
│ ├── module_a.ts # Module A example
│ ├── module_b.ts # Module B example
│ └── database/ # Database singleton examples
│ ├── my-database-function.ts
│ ├── my-database-module.ts
│ └── my-database-singleton.ts
├── package.json
├── tsconfig.json
└── README.md
- Location:
src/creational/singleton/
- Purpose: Ensures a class has only one instance and provides global access to it
- Use Cases:
- Database connections
- File servers
- Print servers
- Import modules
- System configuration objects
Key Features:
- Private static instance attribute
- Private constructor to prevent instantiation with
new
- Static getter method that creates or returns the existing instance
- Thread-safe implementation
Example Usage:
const database1 = MyDatabaseSingleton.instance;
const database2 = MyDatabaseSingleton.instance;
// database1 === database2 (same instance)
npm test
- Run tests (currently not configured)
The project is configured with:
- TypeScript: For type safety and modern JavaScript features
- ESLint: Code linting with TypeScript support
- Prettier: Code formatting
- ts-node: Direct TypeScript execution
tsconfig.json
: TypeScript compiler configuration.eslintrc
: ESLint configuration with TypeScript and Prettier integration
Each pattern implementation includes:
- Detailed explanations in markdown files
- Practical examples with real-world scenarios
- Code comments explaining the implementation details
- Multiple usage examples demonstrating different approaches
This is a study project, but contributions are welcome! Feel free to:
- Add new design patterns
- Improve existing implementations
- Add more examples and use cases
- Enhance documentation
- Add more creational patterns (Factory, Builder, Prototype)
- Implement structural patterns (Adapter, Decorator, Facade)
- Add behavioral patterns (Observer, Strategy, Command)
- Include unit tests for all patterns
- Add performance benchmarks
- Create interactive examples
Dheyson Alves
This project is licensed under the ISC License.
- Design Patterns: Elements of Reusable Object-Oriented Software
- TypeScript Documentation
- Refactoring Guru - Design Patterns
Happy coding and learning! 🎉