Facade pattern in PHP

The facade pattern is today’s structural design pattern. My previous two blogs were about the adapter and the decorator patterns and just like these pattern, the facade pattern is also a known as a wrapper.

The facade pattern does have some similarities to the adapter pattern, in that they’re both used to modify the interface of an entity. However the decorator pattern is used in a very different manner. In case you forgot, here is a quick run down.

Pattern Purpose
Adapter Used to allow incompatible interfaces to work together.
Decorator Allows behaviours to be added to an object, without modifying the original class.
Facade Provides a simplified interface to a more complex library.

Continue reading

Decorator pattern in PHP

The decorator pattern is another structural pattern. The aim of the decorator pattern is to extend an existing classes functionality without modifying existing classes and rather using composition to wrap and extend the existing functionality.

Using Decorators, existing behaviours will stay the same, but you will have additional behaviour extensions which can be used to modify the output.

Continue reading

Adapter Pattern in PHP

Now we have covered all of the creational patterns you should know about (imo). I am steaming ahead on to the structural patterns. The first of which is the adapter pattern 😀

In programming, it’s not rare to build a system, to find out a few months down the line, there are a bunch of new requirements. Originally catering for a particular client or data set and then later having to cater for more and more, this is where the adapter pattern comes into play.

Continue reading