Welcome to the "Design Patterns in TypeScript" repository! In this project, you can explore various design patterns that provide conceptual as well as real-world examples of their implementation using TypeScript. This repository serves as a learning resource for developers interested in design patterns and TypeScript. Thank you for checking out this repository, this project was a way for me to learn popular design patterns while strenghtening my OOP and TypeScript skills. A great reasource for learning more about the design patterns in this repository and seeing examples in many top programming languages can be found here.
Design patterns are reusable solutions to common problems that software developers encounter during the design and development of software applications. They provide a structured and proven approach to solving these problems, enhancing the maintainability and readability of your code. See the following for a list of design patterns in this repository.
-
Factory Method: Link to Factory Method Examples
-
Abstract Factory: Link to Abstract Factory Examples
-
Builder: Link to Builder Examples
-
Prototype: Link to Prototype Examples
-
Singleton: Link to Singleton Examples
-
Adapter: Link to Adapter Examples
-
Bridge: Link to Bridge Examples
-
Composite: Link to Composite Examples
-
Decorator: Link to Decorator Examples
-
Facade: Link to Facade Examples
-
Flyweight: Link to Flyweight Examples
-
Proxy: Link to Proxy Examples
-
Chain of Responsibility: Link to Chain of Responsibility Examples
-
Command: Link to Command Examples
-
Iterator: Link to Iterator Examples
-
Mediator: Link to Mediator Examples
-
Memento: Link to Memento Examples
-
Observer: Link to Observer Examples
-
State: Link to State Examples
-
Strategy: Link to Strategy Examples
-
Template Method: Link to Template Method Examples
-
Visitor: Link to Visitor Examples
The repository is organized into subdirectories, each corresponding to a type of design pattern. In each of those there is a directory for all the specific design pattern. Inside each design pattern directory, you will find TypeScript source code along with compiled JavaScript files. You will find a conceptual example of the design pattern named conceptual.ts
along with one or more real-world examples named after the real-world problem they represent. Additionally, there will be a README.md
file that explains the design pattern and provided examples.
To explore and learn from the design patterns implemented in this repository, you can follow these steps:
- Navigate to the specific design pattern directory you are interested in (e.g.,
Creational-Patterns/Factory-Method/
). - Inside each design pattern directory, you'll find TypeScript and JavaScript files. The
conceptual.ts
file provide a basic understanding of the design pattern, while the other examples demonstrate how the pattern is used in a practical scenario. On top of the TypeScript files there also is the compiled JavaScript file that can be ran using node to examine how the design pattern function and the output. - Read the
README.md
file in each directory to get an overview of the design pattern and learn how to use it. - Examine the TypeScript source code and compiled JavaScript files to see the pattern in action.
- Experiment with the code, modify it, and use it as a reference for your projects.
These steps should help you clone the repository, navigate to specific design pattern directories, run JavaScript code, and recompile and run updated TypeScript code as needed. Ensure that you have Node.js and tsc installed as they are both needed.
-
Clone the Repository: To get started, open your terminal or command prompt and use the following command to clone the repository to your local machine:
git clone https://github.com/paytonshafer/Design-Patterns.git
-
Change Directory: Navigate to the cloned repository's root directory using the
cd
command:cd Design-Patterns
-
Navigate to a Design Pattern Directory: Choose a specific design pattern directory you want to explore (e.g.,
cd Creational-Patterns/Factory-Method
):cd <Type-of-Pattern>/<Pattern-Name>
-
Run JavaScript Code: Inside the chosen design pattern directory, locate the JavaScript files (
.js
) and use Node.js to run them (e.g.,node conceptual.js
):node <file-name>.js
This will execute the JavaScript file named
<file-name>
.
-
Edit TypeScript Code: If you want to make changes to the TypeScript code, navigate to the TypeScript source code files (
.ts
) in the design pattern directory and edit them using your preferred code editor. -
Recompile TypeScript Code: After making changes to the TypeScript code, you need to recompile it into JavaScript. Use the TypeScript compiler (tsc) to do this:
tsc
This command will compile all TypeScript files in the current directory.
-
Run the Recompiled JavaScript Code: Once the TypeScript code is successfully recompiled, you can run the updated JavaScript code using Node.js, as described in step 4.
-
View Changes: Observe the effects of your changes by running the recompiled JavaScript code.
This project is licensed under the MIT License - see the LICENSE file for details.