Here are code examples of each SOLID principle written in C# with .NET Core
Every module, class or function in a computer program should have responsibility over a single part of that program's functionality, which it should encapsulate.
The reason it is important to keep a class focused on a single concern is that it makes the class more robust.
Software entities should be open for extension but closed for modification.
The risk of changing an existing class is that you will introduce an inadvertent change in behaviour.
The solution is create another class that overrides the behaviour of the original class.
By following the OCP, a component is more likely to contain maintainable and re-usable code.
Child classes should never break the parent class’ type definitions.
The concept of this principle was introduced by Barbara Liskov in a 1987 conference keynote and later published in a paper together with Jeannette Wing in 1994.
As simple as that, a subclass should override the parent class methods in a way that does not break functionality from a client’s point of view.
It is quite common to find that an interface is in essence just a description of an entire class.
The ISP states that we should write a series of smaller and more specific interfaces that are implemented by the class.
Each interface provides an single behavior.
The DIP simply states that high-level classes shouldn’t depend on low-level components, but instead depend on an abstraction.
Adapted from Solid Principles with TypeScript by Samuele Resca
Contributions are always welcome! 👊
You can reach me out at Twitter @luizhp
Give a ⭐️ if this project helped you!
Copyright © 2020 .luizhp
This project is GPL v3 licensed.