Single Responsibility: an object must have only one responsibility.
Open-Close: entities should be open for extension, but closed for modification.
Liskov substitution: client objects that are very specific should be replaced by instances of its subtypes.
Interface segregation: small and specific interfaces are better than a generic interface.
Dependency inversion: do not depend on specific implementations, but abstractions
It is a principle that is focused on better use of object orientation and some techniques such as Dependency Inversion (which also involves dependency injection, so do not get confused). It’s probably one of the most important principles for a well done and well structured code.
It is so important that I’ll not give an example about it here, then it will be in the next post, which I will detail the SOLID.
Don’t Repeat Yourself
It is a principle that is focused on the elimination of duplicates and that repeated logics must be eliminated via abstraction and repeated processes should be eliminated via automation.
Once duplications have directly impact on software maintenance, DRY is a highly recommended principle to always be used.
Example of possible applied DRY:
Keep It Simple, Stupid
It is a principle that is focused on the simplicity of the system and this simplicity must be the goal in design and that unnecessary complexity should be avoided.
Example of possible applied KISS:
What You See Is What You Get
It is a principle that is focused on delivering exactly what you see. Even being more focused on the design, it is an important principle because it does not always happen, as shown in the following example:
Example of a violation of the WYSIWYG:
WHAT WAS PROMISED:
WHAT WAS DELIVERED:
You Aren’t Gonna Need It
It is a principle that is focused on doing the simplest possible thing may work. In many cases, developers create code “in case they need a day.” If you don’t need, that should not be there. Implement only when you really need that.
Example of possible applied YAGNI: