How to write React clean code
-
“a class should have only one reason to change” which means every class should have a single responsibility or single job or single purpose.
Source image: https://levelup.gitconnected.com/the-single-responsibility-principle-made-simple-4e1597a44d7d
-
“software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification” which means you should be able to extend a class behavior, without modifying it.
Source image: https://levelup.gitconnected.com/the-open-closed-principle-made-simple-cc3d0ed70553
-
“Derived or child classes must be substitutable for their base or parent classes“. This principle ensures that any class that is the child of a parent class should be usable in place of its parent without any unexpected behavior.
Source image: https://www.linkedin.com/pulse/liskov-substitution-principle-mamata-raote-she-her-/?trk=articles_directory
-
“do not force any client to implement an interface which is irrelevant to them“. Here you should prefer many client interfaces rather than one general interface and each interface should have a specific responsibility.
Source image: https://levelup.gitconnected.com/interface-segregation-principle-made-simple-990da495441c
-
High-level modules/classes should not depend on low-level modules/classes. Both should depend upon abstractions. Abstractions should not depend upon details. Details should depend upon abstractions.
Source image: https://medium.com/@radheshyamsingh_83359/dependency-inversion-principle-solid-design-78214fe2b64b
Thank you for reading ! 🙏♥
Source: https://www.geeksforgeeks.org/solid-principle-in-programming-understand-with-real-life-examples/
Video: https://youtu.be/MSq_DCRxOxw