Design Patterns can help us write more efficient, maintainable and clearer code. They're time tested solutions to common problems in software design. I've recently taken a closer interest in design patterns and decided to document the types of design patterns I've come across, as they apply specifically to Javascript. A lot of the examples out there are pre-ES2015 and I thought it would be nice to redo them in more mordern syntax.
Please note that not all examples have been converted fully to ES6. It is a work in progress and I'll be refactoring the code as I progress.
Each folder contains a small app which illustrates a design pattern. The folders are named after the design patterns they illustrate. The samples are simplistic and intended only to illustrate the features of each pattern.
You can find articles walking through each design pattern on my Medium. Currently the first article on the Factory Pattern is up. As I add more articles, I'll list the links below:
- Factory Pattern - Link
- Publisher/Subscriber Pattern - Link
- Strategy Pattern - TBD
- Observer Pattern - TBD
- Chain of Responsibility Pattern - TBD
- Mediator Pattern - TBD
- Iterator Pattern - TBD
- Facade Pattern - TBD
- Decorator Pattern - TBD
- Adapter Pattern - TBD
- Composite Pattern - TBD
- Proxy Pattern - TBD
git clone
the repo to a local folder.- Run
npm install
to install the node_modules (this is mainly for nodemon so we can run node with autorefresh enabled) - There are two commands,
npm start
andnpm run start-dev
. - To run the examples, pass in the folder name for the specific design pattern as an npm argument. For example, to run the "factory" design pattern, you would enter the command
PATTERN=factory npm run start-dev
in your temrinal. - The folder names correspond to the design pattern names.
This is still a work in progress and I'll be adding more design patterns
If you have any suggestions or would like to contribute in any way, please feel free to open an issue or make a PR.