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.

Exploring a use case for the adapter pattern

Exploring a use case for the adapter pattern - PHP Tutorial

From the course: PHP: Design Patterns

Start my 1-month free trial

Exploring a use case for the adapter pattern

- In this example, we want to send a notification to two separate users. One via text message and the other via email. So if we look at the first half of the code, lines 13 through 19, we're using a service called Twilio. First we instantiate our object using username and password. Then we use that object to create a text message specifying the from and the to phone numbers, along with the body of the message. The code itself is not complex at all. In the second half of the code, lines 22 through 30, we use a service called SendGrid. First, we instantiate our object using a username and password just like before. Then we use that object to create an email specifying the from and the to addresses along with the body and the subject of the message. While these two snippets don't look very similar, they're doing effectively the same thing by two distinct approaches. So how would we use an adapter here? In this case, we can take a couple different steps. First, we remove the references to…

Contents