Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

StarTutorial.com:
Understanding Design Patterns - Adapter
Jul 23, 2018 @ 15:47:19

The StarTutorial site has posted the next article in their series introducing various design patterns and their use in PHP. In their latest tutorial they cover the Adapter pattern, a useful pattern for putting a unified interface in front of various functionality.

[The Adapter pattern] converts the interface of a class into another interface the clients expect. Adapter lets class work together that couldn’t otherwise because of incompatible interfaces.

In their example they talk about a traveller wanting to charge their devices but being frustrated by the different plugs around the world. This is where an adapter comes in handy, providing a standard method for interaction (the input plug) with a wide range of backend tools (the plugs all around the world). They use this example and built out "plug" and "socket" classes where the adapter class acts as a go-between for the plug and receptacle.

tagged: designpattern tutorial series adapter

Link: https://www.startutorial.com/articles/view/understanding-design-patterns-adapter


Trending Topics: