Programming fundamentals

 A Guide to Solid Principles

Acronym of SOLID


SOLID is a popular set of five design principles that are used in object-oriented software development. These principles are commonly used by software engineers which were developed by Robert C. Martin (also known as Uncle Bob).



  1. Single-Responsibility Principle

This principle states that a class should have one sole purpose furthermore, there should never be more than one reason for a class to change.

Goal

This principle aims to separate behaviours so that if bugs arise as a result of change, it won't affect other unrelated behaviours in the program.


Benefits

    • Testing:

A class with one responsibility will have far fewer test cases which results in very less efforts in testing.

    • Lower coupling:

Less functionality in a single class will have fewer dependencies. Hence, it will lower the coupling.

    • Better Organization:

Smaller, well-organized classes are easier to be searched by a first-time code reader than bigger ones.

    • Easy to implement
    • Easy to maintain

    2. Open-Closed Principle


This principle states that the Classes should be open for extension but closed for modification. In doing so, we stop ourselves from modifying existing code and causing potential new bugs


 

Goal

This principle aims to extend a Class's behaviour without changing the existing behaviour of that class. This is to avoid  causing bugs whenever the Class is being used.

Benefits

    • Better Extensibility

    • Easy to maintain
    • Flexibility

    3. Liskov Substitution Principle



This principle states that subclasses should be substitutable for their super class

In other words, what we want is to have the objects of our subclasses behaving the same way as the objects of our superclass.




 

Goal

This principle aims to enforce consistency so that the Parent Class or its Child Class can be used in the same way without any errors.

Benefits

    • Code Reusability
    • Easy to maintain
    • Reduced Coupling

    4. Interface Segregation Principle

This principle states that a client should not be exposed to methods that they do not need.

larger interfaces should be split into smaller ones. By doing so, we can ensure that implementing classes only need to be concerned about the required methods.

        

Goal

This principle aims at splitting a set of actions into smaller sets so that a Class executes only the set of actions it requires.

Benefits

    • Increased code readability
    • Easy to maintain
    • Easy to implement
    • Better organization of code
    • Don’t need to throw exceptions unnecessarily

    5. Dependency Inversion Principle


This principle states that high-level modules should not depend upon low-level modules; they should depend on abstractions. Secondly, abstractions should not depend upon details. No dependency should target  a concrete class.


        

Goal

This principle aims at reducing the dependency of a high-level Class on the low-level Class by introducing an interface.

Benefits

    • Keeps your code loosely coupled
    • Easy to maintain
    • Code Reusability

      How to Master Software Development Skills

How to tackle a problem:

  1. Identify the Problem.
  2. Gather Information.
  3. Divide the problem until it becomes simple enough to be solved directly.
  4. Keep the Solution Simple.
  5. Iterate over potential solutions.
  6. Anticipate changes to the solution as much as possible.
  7. Test the solution.

How to implement Code:

  1. Write the code that you need at the moment.
  2. Reuse the code whenever possible.
  3. Encapsulate unnecessary details as much as possible.
  4. Do not waste time in solving a problem which has been solved by someone.
  5. Learn to write readable code which makes debugging easier.
  6. Always fix bugs in the application whenever it arises.

Guidelines followed in the development process:

  1. Unit testing: 

    • a testing technique using which individual modules are tested to determine if there are any issues by the developer himself. It is concerned with functional correctness of the standalone modules
      2. Code Quality:
    • The code quality is important, as it impacts the overall software quality. Quality impacts how safe, secure, and reliable your codebase is.
      3. Code Review:
    • Code review is a process to ensure that bugs and errors are caught and fixed before they reach production. It is part of a bigger quality assurance process to ensure that the final product performs exactly as expected.
      4. Version Controlling:
    • Version control systems are software that help track changes make in code over time. As a developer edits code, the version control system takes a snapshot of the files. It then saves that snapshot permanently so it can be recalled later if needed.
      5. Continuous Integration:
    • Continuous Integration (CI) is the process of automating the build and testing of code every time a team member commits changes to version controlIt encourages developers to share their code and unit tests by merging their changes into a shared version control repository after every small task completion.

Comments