This repo demonstrates the SOLID principles with the example of a basic imaginary email service, in which we need to validate the address, send a message, and log the transaction. We'll start with a basic "dirty implementation" and introduce the SOLID concepts one by one.
In the SILOD ("siloed") order:
- Start
SRP
: Begin to break up functionality and make it semantic and clean.ISP
: Working towards interfaces, not concretions.LSP
: Making subclasses without breaking superclasses.OCP
: Extending behavior of superclass methods without breaking them.DIP
: Creating flexibility by decoupling dependencies and injecting them where needed.
You can install the things with npm install
. For running the starting code, run npm start
. Then, for each respective letter of the SOLID principles you want to run, use npm run s|o|l|i|d
.
Or, if you're lazy, you can also copy the individual TS file's contents into the TypeScript playground if you want to avoid cloning and installing anything at all.
The principles in their mnemonic order: