S.O.L.I.D. : 5. Dependency Inversion Principle

Dependency inversion principle is one of the the most important principle because it is related to the high level architecture of a project.

If you are following TDD (test driven development), then you must follow this principle.

The principle states :

  • High level modules should not depend on low-level modules, both should depend on abstractions.
  • Abstractions should not depend on details. Details should depend on abstractions.

Some people does not agree with this rule saying that OOPS says classes and subclasses must depend on the same abstraction.

For better understanding we are taking an exmaple of Worker and Manager class.

 

Now see the cons:

  • We have to modify the Manager class, and some of the functionality of the Manager might be affected.
  • The unit tests should be redone.

If we would have follow the D-IP, we wouldn’t have had these problems.

 

<< Previous Principle

OOPS concepts specific for PHP >>

Please follow and like us:
20

Leave a Reply