4/24/2019 - 12:32 PM

SOLID Principles

The SOLID design principles were promoted by Robert C. Martin and are some of the best-known design principles in object-oriented software development.
SOLID is a mnemonic acronym for the following five principles:

The SOLID concepts are:

  • The Single-responsibility principle: a class should only have a single responsibility, that is, only changes to one part of the software's specification should be able to affect the specification of the class.[5]

  • The Open–closed principle: "software entities ... should be open for extension, but closed for modification."[6]

  • The Liskov substitution principle: "objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program." It extends the Open/Closed principle and enables you to replace objects of a parent class with objects of a subclass without breaking the application. This requires all subclasses to behave in the same way as the parent class. To achieve that, your subclasses need to follow these rules:

    • Don’t implement any stricter validation rules on input parameters than implemented by the parent class.
    • Apply at the least the same rules to all output parameters as applied by the parent class.
  • The Interface segregation principle: "many client-specific interfaces are better than one general-purpose interface."[8][4]

  • The Dependency inversion principle:

    • "depend upon abstractions, [not] concretions."[9][4]
    • The dependency inversion principle states that your application’s abstractions should not depend on implementation details, but rather implementation should depend on abstractions.
    • In the typical layered architecture of an application, a high-level component should not directly depend on a lower-level component. You should create an abstraction (for example, an interface) and make both components depend on this abstraction.

The SOLID acronym was introduced later in 2004 or thereabouts by Michael Feathers.[10] Although they apply to any object-oriented design, the SOLID principles can also form a core philosophy for methodologies such as agile development or adaptive software development.[3]`