A note about solid Principles (Demo in Symfony2)

  1. Single responsibility ( a class have only one reason to change, do not mix up (mess up) everything in a class)
  2. Open for extend, close for modification( move common behavior to interface, flip injection – Uncle Bob)
  3. Liskov Substitution Principle, eg: same output format (array , json, specify type of Type- signature must match, preconditions cannot be greater, post conditional at least equal to, exception type must match). All of the derived class (sub class) could be substitutable (interchangeable)
  4. A client should not be forced to implement an Interface that it does not use (return null in a override function ) – split fat interface to smaller interface.
  5. The higher level of inheritance should not depend on the low level of code, it should depend on the abstract class (Inversion of control, Dependency inversion not Dependency injection, not opposite, but complementary) – decoupling code

note:
class extends 1 class, implements multiple interfaces (like java)
interface extends interface
class implement an interface must override all methods

Demo link:
https://github.com/nguyentienlong/solid-principles-demo

Reference:
https://laracasts.com/collections/solid-principles

TODO: translate to Vietnamese, add more code and explanation