Created
August 27, 2019 21:01
-
-
Save seanhagen/f2de4b06e7ab49e1e718be5bff2b408d to your computer and use it in GitHub Desktop.
Interface/API Design Question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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