PHP Object-Oriented Programming Cheat Sheet

OOP Concepts, S.O.L.I.D Principles, Design Principles

Inheritance

When an object or class is based on another object or class, using the same implem​ent​ation; it is a mechanism for code reuse. The relati​onships of objects or classes through inheri​tance give rise to a hierarchy.

Encapsulation

Enclosing objects in a common interface in a way that makes them interc​han​geable, and guards their states from invalid changes.

Abstraction

The process of separating ideas from specific instances of those ideas at work.

Polymorphism

The provision of a single interface to entities of different types. Subtyping.

Single Responsibility Principle

A class should have only one reason to change.

Open-Closed Principle

Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.

Liskov Substitution Principle

Subtypes must be substitutable for their base types.

Interface Segregation Principle

No client should be forced to depend on methods it does not use.

Dependency Inversion Principle

A. High-level modules should not depend on low-level modules. Both should depend on abstractions. B. Abstractions should not depend upon details. Details should depend upon abstractions.

Don't Repeat Yourself

Avoid duplicate code by abstra​cting out things that are common and placing those things in a single location. DRY is about having each piece of inform​ation and behavior in yo

Favor Composition over Inheritance

Use behavior from a family of other classes, and change that behavior at runtime.

Encapsulate What Changes

Identify the aspects of your application that vary and separate them from what stays the same.

Program to Interface, not Implementation

Don't depend on a concrete type to do your work.
Did we miss anything? Did you find any mistakes we made? Do let us know via our contact form.