Skip to content

Practical examples of common design patterns implemented in TypeScript

Notifications You must be signed in to change notification settings

laszlo-horvath/design-patterns-in-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypeScript Design Patterns Examples

This repository contains practical examples of common design patterns implemented in TypeScript. Each example is designed to be simple, understandable, and relevant to real-world web development scenarios.

Getting Started

  1. Clone the repository
  2. Install dependencies
  npm install
  1. Run any pattern example using the npm scripts
  npm run design-pattern:<pattern-name>

Available Patterns

1. Factory Pattern (Creational Pattern)

Demonstrates object creation through a notification system, showing how to create different types of notifications (email, SMS, push) using a common interface.

  npm run design-pattern:factory

2. Singleton Pattern (Creational Pattern)

Shows how to ensure a single instance of a database connection is shared across the application.

  npm run design-pattern:singleton

3. Adapter Pattern (Structural Pattern)

Illustrates how to make incompatible interfaces work together using payment provider integration as an example.

  npm run design-pattern:adapter

4. Decorator Pattern (Structural Pattern)

Demonstrates how to add new behaviors to objects dynamically using logging and performance measurement examples.

  npm run design-pattern:decorator

5. Repository Pattern (Data Access Pattern)

Shows how to abstract data access logic using a simple user management system.

  npm run design-pattern:repository

6. Observer Pattern (Behavioral Pattern)

Shows how objects can notify other objects of state changes using a weather station example with multiple displays.

  npm run design-pattern:observer

About

Practical examples of common design patterns implemented in TypeScript

Topics

Resources

Stars

Watchers

Forks