Decorator

A Decorator is simply what adds additional functionality to an individual class without affecting the behavior of other objects from the same class.

The Single Responsibility Principle, simply put by Robert C. Martin (who I introduced at the start of this chapter), is that a class should have only one reason to change.

The principle states that every module or class should have a single responsibility and that responsibility should be entirely encapsulated by that class. All services of the class should align with that responsibility. Martin summarized this by defining the responsibility as follows:

"a charge assigned to a unique actor to signify its accountabilities concerning a unique business task".

By using the Decorator design pattern, ...

Get Mastering PHP Design Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.