🌱 SOLID principals

code that is hard to change is bad design

1. Single responsibility

2. Open-closed

software is open for extension; original source closed for modification

Separate extensible behavior behind an interface and flip the dependencies

Square, Circle, Triangle -> Shapes AreaCalculator class

polymorphic : different behavior behind a common interface

3. Liskov Substitution

B should be able to be substituted anywhere A is used in the codebase.

class A {
    public function fire() {}
}

class B extends A {
    public function fire() {}
}

return values should be of the same type for methods in an interface

if you have to do type checking you are probably breaking a SOLID principal

  1. signature must match
  2. preconditions can’t be greater
  3. post conditions at least equal to
  4. exception types must match

4. Interface segregation

Clients should never be forced to implement interfaces they don’t use.

Prevent ripple effects.

5. Dependency Inversion

High-level modules should depend on abstractions not lower level modules. Both should depend on abstraction(contract or interface).

Decouple code.

High level code : not concerned with details

Low level code : concerned with details

Class should depend on an interface not an implementation

Made by Brandon . If you find this project useful you can donate.