Skip to content

Instantly share code, notes, and snippets.

@seanhagen
Created August 27, 2019 21:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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