Module 15 Β· Design Patterns in Go β Lesson 7 of 8 Β· ~6 min
Adapter
Make a foreign type fit the interface you expect
Adapter wraps a type with the wrong interface so it satisfies the one your code uses. PawWalk sends through a Notifier with Send(msg string) error. But the legacy mailer you must reuse only offers Deliver(text string) β different name, no error return. You can't edit it (it's a vendor package), and you don't want to rewrite every caller.
So you wrap it. A small struct embeds or holds the legacy value and exposes a Send method that translates the call. Thanks to Go's implicit interfaces, the moment your adapter has a Send(string) error method, it is a Notifier β no declaration required.