Skip to content

Instantly share code, notes, and snippets.

@seanhagen
Created August 27, 2019 21:01
Show Gist options
  • Save seanhagen/f2de4b06e7ab49e1e718be5bff2b408d to your computer and use it in GitHub Desktop.
Save seanhagen/f2de4b06e7ab49e1e718be5bff2b408d to your computer and use it in GitHub Desktop.
Interface/API Design Question
package email
import (
"context"
)
// Version 1
// Sender is an interface to hide the fact we're using a 3rd party library
type Sender interface {
// NewMessage sets up a basic email message that's ready to send
NewMessage(sender, subject, body, recipient string) *MessageImpl
// Send attempts to send the email -- if successful returns a human-readable status message & a message ID
Send(context.Context, Message) (string, string, error)
}
type Message interface {
AddAttachment(string)
}
// VS
// Version 2
type Sender interface {
NewMessage(sender, subject, body, recipient string) *MessageImpl
}
type Message interface {
AddAttachment(string)
Send(context.Context) (string,string, error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment