Module 15 Β· Design Patterns in Go β Lesson 3 of 8 Β· ~6 min
Factory
A constructor that returns an interface
Factory hides which concrete type gets built behind a function that returns an interface. When a booking changes, PawWalk notifies the owner β by SMS, email, or push. Callers shouldn't scatter if channel == ... everywhere; they ask a factory for a Notifier and call Send.
This is where Go's implicit interfaces shine: SMSNotifier and EmailNotifier never declare that they implement Notifier β having the right method is enough. The factory returns the interface; the concrete type is an implementation detail the caller never sees.