Showing posts with label Dependency Inversion. Show all posts
Showing posts with label Dependency Inversion. Show all posts

Friday, October 9, 2015

SOLID principles

From Wikipedia:   In computer programming, SOLID (Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion) is a mnemonic acronym introduced by Michael Feathers for the "first five principles" named by Robert C. Martin in the early 2000s.


Initial Stands for
(acronym)
Concept
S SRP [4]
Single responsibility principle
a class should have only a single responsibility (i.e. only one potential change in the software's specification should be able to affect the specification of the class)
O OCP [5]
Open/closed principle
“software entities … should be open for extension, but closed for modification.”
L LSP [6]
Liskov substitution principle
“objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.” See also design by contract.
I ISP [7]
Interface segregation principle
“many client-specific interfaces are better than one general-purpose interface.”[8]
D DIP [9]
Dependency inversion principle
one should “Depend upon Abstractions. Do not depend upon concretions.”[8]
And going more in detail with Dependency Inversion, the principle states:
A. High-level modules should not depend on low-level modules. Both should depend on abstractions.
B. Abstractions should not depend on details. Details should depend on abstractions.

Abstraction dependency

The presence of abstractions to accomplish DIP have other design implications in an Object Oriented program:
  • All concrete class packages must connect only through interface/abstract classes packages.
  • No class should derive from a concrete class.
  • No method should override an implemented method.[5]
  • All variable instantiation requires the implementation of a Creational pattern as the Factory Method or the Factory pattern, or the more complex use of a Dependency Injection framework.