396 likes
·
7.2K reads
27 comments
Great article Francesco!
Thank you Sunil and thanks for the following!
Loved it.
Thank you Mohd, really appreciated!
I once took a course on Design Principles, dumped it before I could finish off the second module, which was about the SOLID principle.
Wish I had seen this. Amazing write-up, Francesco!
Thank you Gyen! I hope it was useful as a refresher!
What a start .. Loved it
Thank you Mohit! I will check your articles!
Welcome Francesco Ciulla :)
Great Article Francesco Ciulla!!! Good to see you here :)
Thank you Apoorv...I am just a little late on this 😂
Haha. No worries
Fantastic and insightful article Francesco Ciulla. Thanks for sharing.
Hey Edidiong! You have a different picture on Twitter but I recognize you! :)
Thank you so much!
Francesco Ciulla, Awesome writeup, and great content.
Question: Are the images snaps taken from the white-board or using a tool? They look awesome and very relevant to each of the sections. Nice work!
Awesome write-up Francesco! Love SOLID principles
Thank you Chris!
Lovely article!
Thank you Maximilian!
Francesco You're welcome :).
Awesome article! Thanks!
you are welcome Peter ....😂
Well, Explained! I read them many times but I wasn't clear about the last three. It's really well explained. Many thanks!
Thank you Salil!
The visuals definitely help people get the gist of every principle. Then, coding becomes easy.
Good article, Francesco Ciulla!
Thank you!
Hi Francesco, how you formulate and present information is inspiring. So simple and straightforward. I like it a lot and love to absorb such a material.
As regards SRP, both compositions under "No" and "Yes" examples are not violating the principle. They compose two things — validation and creation of the user. This function isn't an operation. It's a composition. Operations are testForm()
and createUser()
. They shall comply with SRP. And the composition composes operations, it's a control flow.
How about to rename validateRequest()
function to something like createValidUser()
in favor to clarify composition happening within?
What both examples violate is DIP, the last one from SOLID. Because they compose testForm()
function and createUser()
which become direct dependencies. We can't exchange them, if we need to run a different validation, for example.
To comply with DIP, we could inject them both into a composition.
createValidUser = (req: Request, validate: ValidateForm, createUser: CreateUser): void => {
const { name, password, email } = req.body;
if (validate(name, password, email)) {
createUser(req);
}
throw new Error…
}
Voilà, now our composition createValidUser()
function would depend on interfaces, not on implementations details.
When composition composes various operations it doesn't violate SRP. It contains a control flow of a program, which developers maintaining this code could clearly understand without looking at the implementation details of operations being composed.