Category: design pattern

The Balance between Visual and Technical Debt in PHP

Laracasts recently published a very interesting non-Laravel video about something called visual debt. It’s only 3 minutes long, so please, take the time to watch it before reading further.Done? Okay, spoilers below.In the video, Jeff starts out with with a bit of verbose event-based code with some listeners, ...

Achieving Modular Architecture with Forwarding Decorators

As your web application becomes larger, you certainly start to think more about designing a flexible, modular architecture which is meant to allow for a high amount of extensibility. There are lots of ways to implement such architecture, and all of them circle around the fundamental principles: separation of concerns, ...

Quick Tip: The Convenient Magic of Eloquent Observers

If you’ve used Eloquent on medium to large projects before, you may have encountered a situation where you want to take action when something happens to your models. Eloquent provides a convenient way to do so.The Observer PatternThe observer pattern is a software design pattern in which an object, called the...

Disco with Design Patterns: A Fresh Look at Dependency Injection

Dependency Injection is all about code reusability. It’s a design pattern aiming to make high-level code reusable, by separating the object creation / configuration from usage.Consider the following code: <?phpclass Test {protected $dbh;public function __construct(PDO $dbh) { ...

Command Buses Demystified: A Look at the Tactician Package

Command Buses have been getting a lot of community attention lately. The topic can be quite overwhelming at first when trying to understand all the concepts and terminology, but in essence – what a Command Bus does is actually incredibly simple. In this article, we’ll take a closer look at variations of the Com...

Flyweight Design Pattern and Immutability: A Perfect Match

The flyweight pattern is a relatively unknown design pattern in PHP. The fundamental principle behind the flyweight pattern is that memory can be saved by remembering objects after they have been created. Then, if the same objects need to be used again, resources do not have to be wasted recreating them.You can think...