Skip to main content

What are SOLID Principles? Explained with OOP Concepts.

 What are SOLID Principles? Explained with OOP Concepts.

What are SOLID Principles? Explained with OOP Concepts.
SOLID Principles

Software developers implement codes to meet the users' requirements and satisfy the clients. Some principles have to follow by software developers to enhance their code writing skills.

The SOLID principles have considerable responsibility to guide the software developers, to make the software design by improving the code quality. 


An American software engineer named Robert C.Martin created this principle.


Why do we need SOLID principles?

Advantages of using SOLID Principles.

  • Make the code more understandable and readable.
  • Make the code snippet as simple as possible by reducing the complexity.
  • Make the lines of codes flexible. Therefore the code snippets are updatable or modifiable when required.
  • To maintain the software codes easily.
  • To reduce the dependencies.
  • To make the code testable.
  • To implement the code. 

Solid principles have five(5) principles. The name is created by considering the first five letters from each principle. 

5 SOLID Principles
5 SOLID Principles
            

 Let us have a look at each of the principles separately.


          1. S - Single Responsibility Principle

This principle explains that a class has to contain one responsibility.


Example:

Let us assume a stock management project is implemented for a textile shop. There are many different teams, and they have to change one particular class to implement some functionalities due to distinct purposes. So the modified classes will become complex and incompatible due to several changes.


           2. O - Open Closed Principle

This principle explains that a class can handle extensions without being modified. So if we need to add some functionalities to previous classes, it is better to create another abstract class or interface and include the functionalities. It helps to save implementing time. 


Example:

Let us assume there is a student management system for a university. The students can be undergraduate students or post-graduate students. There can be some attributes that are common for both classes. Then the undergraduate students and post-graduate students can be considered as child classes and the person as the parent class to store the common attributes. So both the child classes inherit the parent class.


          3. L - Liskov Substitution Principle.

This principle explains that the parent class has to be substitutable with the child class.


          4. I - Interface Segregation Principle.

This principle explains the separation of the interfaces.

Due to the separation of the interfaces, a particular client will be given access to relevant functionalities. That particular client will not access the interfaces that are irrelevant.


          5. D - Dependency Inversion Principle.

This principle explains that the classes have to depend on interfaces or abstract classes. It should avoid the dependability of concrete classes or functions. This principle helps to enhance the reusability of the code.


Conclusion

Thanks for reading my blog by spending your time. I hope this blog will help you to gain knowledge about solid principles.


If you like this blog, share it and show some love.


You can read more of my future blogs by following me through my social media.

LinkedIn  Twitter   Dev Community


References

  • https://medium.com/backticks-tildes/the-s-o-l-i-d-principles-in-pictures-b34ce2f1e898
  • https://www.digitalocean.com/community/conceptual_articles/s-o-l-i-d-the-first-five-principles-of-object-oriented-design
  • https://www.bmc.com/blogs/solid-design-principles/#:~:text=SOLID%20is%20an%20acronym%20that,some%20important%20benefits%20for%20developers.

Comments

Popular posts from this blog

7 Programming Tips For Developers (Beginners)

Beginners initially get scared when started coding. This blog is to help beginners. It will help to avoid the fear and make you more confident. 1. Code daily. “Practice makes a man perfect ” Practicing coding every day helps to overcome the fear of coding. It helps to improve our coding skills and build confidence step by step. Do not get demotivated at the initial stages. During the initial stages of coding, it takes more time to implement a function, takes many days to solve an error. It is totally fine. Every developer faced the same issue at the beginning, therefore you are not the first person to face this problem, and get stressed. Everything will be ok when you start coding continuously. When you start coding, you identify the mistakes and solve the problem by searching through the internet. You try to resolve the errors by yourself. When the problem is not solved, you can get help from other developers or colleagues. There are many resources to get help through the interne...

Microservices

The software architecture is responsible for organizing the software structures (components, interactions of the components with each other, environment, principles used to design the software product). A software architect is a person who is responsible for design architecture for a particular application.  The software architect’s functions are, 1. Identify the system’s structure. 2. Identify the use-cases relevant to different scenarios. 3. Organize the user requirements (functional and non-functional) There are many software architectures. When developing an application, the most suitable architecture has to be selected. Fault selection of architecture leads to the failure of an application where the time and allocated budget will become useless. Micro-services  Micro-services is an architecture, which has Service Oriented Architecture (SOA). SOA has an application scope. It is suitable for a large-scale application. The micro-service architecture uses to develop an applic...