Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
Created January 26, 2023 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arriqaaq/1ec6130a03c296eb107efa661e107c30 to your computer and use it in GitHub Desktop.
Save arriqaaq/1ec6130a03c296eb107efa661e107c30 to your computer and use it in GitHub Desktop.
type Database interface {
SaveData(data string) error
}
type MySQL struct {
// fields and methods
}
func (m *MySQL) SaveData(data string) error {
// code to save data to MySQL
}
type ProcessData struct {
db Database
}
func (p *ProcessData) SaveData(data string) error {
return p.db.SaveData(data)
}
func main() {
db := &MySQL{}
process := &ProcessData{db: db}
process.SaveData("data")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment