Entry #9: Understanding the SOLID Principles

The section “Understanding the SOLID Principles” from the book "Ace the Programming Interview: 160 questions and answers for success" by Edward Guinness talks about the SOLID Principles which help you manage dependencies between classes and encourage class cohesion. These principles are also helpful to code effective module designs using Object-Oriented programming.

The SOLID principles are explained as following:
  • Single Responsibility Principle (SRP): This principle states that a class should have only one responsibility and one or more reasons that cause that class to be changed. The SRP can help us to identify classes during the Design phase of Software Development.
  • Open/Closed Principle (OPC): This principle states that a class or function should be open for extension but closed for modification. Making a flexible design involves additional time and effort and it can introduce a higher level of abstraction, thus increasing the complexity of the code.
  • Liskov Substitution Principle (LSP): This principle talks about interfaces and how to decide when to extend a class or when to use another strategy such as composition to accomplish the requirements. This principle can be resumed to avoid using inheritance and try to use composition.
  • Interface Segregation Principle (ISP): This principle states that we should not have big interfaces to be implemented in classes that may cause them to have useless methods. Instead, we should create a collection of small interfaces based on groups of methods or functionalities, each one serving one submodule.
  • Dependency Inversion Principle (DIP): This principle is applied when high-level classes are not working directly with low-level classes, as they are using interfaces in an abstract layer. Using this principle implies an increased effort, however, it will result in a complex, but flexible code.
Each principle explains that software must have the least possible dependencies, so the product becomes intuitive, logical and practical. These principles are like guidelines that can help us when coding complex systems with a lot of components. The SOLID principles are not just useful in the design phase, but through all the software development process.

Book: Guinness, E. (2013). Ace the Programming Interview: 160 Questions and Answers for Success. Recovered from http://34.212.143.74/s202011/tc3049/solid.html

Comentarios

Entradas populares