class My_Plugin { public static $instance; } is not OOP. A Singleton in every file, hooks added in the constructor, nothing testable. This module takes the tutorial habits apart and replaces them with interfaces, composition and dependency injection without a framework.
| Course | PHP for WordPress Developers · Module 4 of 9 · Stage 2 "Architecture" |
| Learn | Classes, interfaces, traits, composition and dependency injection, with hooks registered outside the constructor |
| How | Short lessons with code from real plugins, IDE practice in the browser, interview questions after every lesson |
The idea in one picture
flowchart LR
P["Plugin bootstrap"] --> S["Service<br/>depends on an interface"]
I["Interface<br/>Storage"] -. implemented by .-> O["Options_Storage"]
P -- "injects" --> O
O --> S
classDef step fill:#f5f3ff,stroke:#777BB4,color:#1e1b4b
classDef key fill:#777BB4,stroke:#4f5b93,color:#ffffff
The service asks for an interface, the bootstrap decides which class it gets. That is dependency injection without a container.
Before → after
| Before | After Module 4 |
|---|---|
::get_instance() in every class | Objects created once and passed in |
add_action() inside __construct() | A separate register() method |
| Deep inheritance chains | Composition over inheritance |
| Classes you cannot test | Dependencies behind interfaces |
You'll be able to answer
- Why is Singleton considered an anti-pattern in WordPress plugins?
- What is dependency injection and how do you do it without a framework?
- When do you choose an interface, an abstract class or a trait?