桥接模式
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/062471aee0eadcbd020e3d9d6568e036.png)
package bridge
type IMsgSender interface {
Send(msg string) error
}
type EmailMsgSender struct {
emails []string
}
func NewEmailMsgSender(emails []string) *EmailMsgSender {
return &EmailMsgSender{emails: emails}
}
func (s *EmailMsgSender) Send(msg string) error {
return nil
}
type INotification interface {
Notify(msg string) error
}
type ErrorNotification struct {
sender IMsgSender
}
func NewErrorNotification(sender IMsgSender) *ErrorNotification {
return &ErrorNotification{sender: sender}
}
func (n *ErrorNotification) Notify(msg string) error {
return n.sender.Send(msg)
}