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

Go Language And Its Environment Set Up

  Go Language And Its  Environment  Set Up Features of Go language Go is a programming language, which is designed by Google(2007). Why it is introduced? 1. Limitations in the hardware. The performance of the system has to be increased. Using a large number of hardware parts like the transistor and the processor, which is not possible. When one of them increases the cost will increase or the performance will reduce. 2. The code is easy to maintain The code written with Go language has a simple and understandable syntax. These features help to maintain the code easily. Features of Go language Open-source. Used at the backend. Made of packages Performance is greater. Has garbage collection. Easy to read the code. Throughput is better. Has garbage collection. How to set up the environment to start coding in Go language. Initially go to  The Go Programming Language (golang.org)  and download Go language by clicking the relevant link(select the correct Operating System). Download Go Click o

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 application and