S.O.L.I.D Principles : week 1

     S.O.L.I.D principle is a coding standard which should be known by every developer in order to produce a proper software without failures and bugs. It was promoted by Robert C Martin. Intention of this principle is to make software designs more understandable, easier to maintain and easier to extend. S.O.L.I.D stands for single responsibility principle, open-closed principle, Liskov substitution principle, interface segregation and dependency Inversion principle.
     Single responsibility means a class should have only one job. As a example take the example of developing a software. Here the task is divided into different members doing different things as front end developers do design, testers do testing and back end developers do back end development. As this we can say everyone has a single job.
     Open-Closed principle means we can extend a class behaviour without modifying it. If you want to add a new feature to a framework or software you are allowed to extend the existing class without modify the class directly. This helps to provide better stability, maintainability and minimises the changers in our code.
      Liskov's substitution principle was introduced by barbara Liskov. This means any class that is the child of a parent class is usable in place of its parent without any unexpected behaviour. As an example a rectangle having four sides where length is different from its width. A square is a rectangle with same length and width. So we can extend the properties of the rectangle class into square class. By swapping child class(square) with its parent class(rectangle) you can do this.
      Interface segregation principle means you should not force any client to implement an interface which is irrelevant to them. It means if you go to a restaurant and you are a pure vegetarian and the waiter gives you a menu card where it has all the vegetarian and non vegetarian items. It seems like you are forced to buy anything. Here the menu should be different for different type of customers. Like this general interface should be divided into many client interfaces and each of them should have a specific responsibility.
      dependency inversion principle means depend on abstraction, not on concretions. The main motive of this principle is decoupling the dependencies. So if class A changes, class B doesn't need to care or know about the changes. For an example for the TV remote you need a battery and you can use any type of battery brand and it still works. So we could say the TV remote is loosely coupled with the brand name.
      Following S.O.L.I.D principle will give you many benefits. if you follow single responsibility principle your code will be easier to follow, understand, debug, remove and refactor. It will be easy to change your code any time. By following open-closed principle changes and usage of objects become cheap. By following Liskov substitution principle new objects can be integrated fast. If you follow interface segregation you do not need to handle the functions that you don't need. It means you need less code, fewer problems and closer deadlines. By following dependency inversion principle you can change the code more easily. Libraries get out dated, business people change their mind and technical requirements change. If our code uses a dependency from outside changing it will be cheaper and we can test our units of code. So knowing these principles is an important thing as a developer.         
        
     
               

Comments

Popular posts from this blog

Node.js VS Java And Usage Of Node.js : week 3