From the course: PHP: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Introducing the publish/subscriber pattern

Introducing the publish/subscriber pattern - PHP Tutorial

From the course: PHP: Design Patterns

Start my 1-month free trial

Introducing the publish/subscriber pattern

- Now let's talk about the publish/subscriber pattern or simply, Pub/Sub. It's one of the more unique patterns we'll cover in this course in that it doesn't deal with the creation of objects or modifying their behavior. Instead it deals with sending and receiving commands to those objects. The problem here is simple. When we build systems the components have to link to one another. The general way of doing this is hard coding connections between the components. A calls B, which calls C. This all works out well until you need to add components D and E. You end up with more and more connections which becomes impossible to manage. We need a way to auto wire these components without explicitly wiring them. Luckily there's a pattern for that, Pub/Sub. The concept is simple. You have some shared channel or communication bus where publishers send their messages. Then you have a series of subscribers that are listening to that channel for messages they care about. When they detect messages…

Contents