SOLID Principles with Motherhood Real-time Examples
Suheda Pehlivan
Software Developer in Test at Turkish Airlines Technology | ISTQB Certified | SDET | Designer | MA in Cultural Studies
SOLID principles are designed by Robert C. Martin with the purpose of understandable & clean code, easy to maintain & extension. SOLID is used in Object Oriented Programming (OOP) principles.?
I will explain SOLID principles with real-time examples from motherhood.
1- Single Responsibility Principle (S)
A class or a method should have only one single responsibility. This principle is totally different from motherhood. A mother has always more than one responsibility. At the same time, she takes care of the children, works, cooks, cleans, etc. In order to understand Single Responsibility Principle, we should think totally opposite of motherhood. A class or a method should just cook, or just clean!
2- Open-Closed Principle (O)
A class or method should not allow changes inside, but it should be open to extension. This principle requires a project should be expandable and unmodifiable. Just like motherhood! When a mother's second child is born, her love for her first child does not change, her heart expands for her second child. That's why a mother's heart is very similar to the Open-Closed Principle, it is expandable and unmodifiable.?
Tip: Use interface or Abstract class in order to extend.
领英推荐
3- Liskov's Substitution Principle (L)
Objects in a project should be replaceable! Subclasses should be able to be used instead of superclasses without making any changes to the code. If it contains unnecessary features, we should create a separate interface for them and make the feature optional.?
From the motherhood perspective, there is no problem when a child inherits a feature from his/her mother. Inherited features are replaceable and usable between mother and children just like Liskov's Substitution Principle.
Tip: Kids can inherit all of our features, be nice!
4- Interface Segregation Principle (I)
The purpose of the Interface Segregation Principle is to create separate interfaces instead of one general interface. Therefore, for every specific feature, we should create a separate interface to contain only relevant methods. In other words, we should create specific interfaces such as cooking mother, cleaning mother, and working mother instead of a general motherhood interface.
5- Dependency Inversion Principle (D)
A class should not depend on another concrete class, so abstract class and interface are used. Because changes in the subclass should not affect the superclass. This makes it easy to test and maintain. From the motherhood perspective, for the mental health of the mother and the child, they need a structure that will make the relationship between them quality. In SOLID this structure is an interface, in motherhood it is a little personal "me time"!
At the beginning of my QA Automation Test Engineer career with my 2 amazing children, I would like to explain the SOLID principles to achieve a "Clean Code" with an example of motherhood, I hope it will be useful for you!
Senior Business Analyst
1 年Great explanation, keep on writing! ??
QA Automation Engineer -| Java | Selenium | TestNG | Junit | Cucumber BDD |API | Postman- REST Assured | SQL | Agile |Git-Github | Jira-Jira xray |
1 年wonderfull.. ?? Thank you.
ISTQB? Certified Software Test Engineer
1 年Inspirational !!
ISTQB? Certified Software Test Engineer || SDET || QA Engineer
1 年What a nice article ????????