November 2018
Intermediate to advanced
346 pages
8h 12m
English
DI is coding in such a way that those resources (that is, functions or structs) that we depend on are abstractions. Because these dependencies are abstract, changes to them do not necessitate changes to our code. The fancy word for this is decoupling.
The use of the word abstraction here may be a little misleading. I do not mean an abstract class like you find in Java; Go does not have that. Go does, however, have interfaces and function literals (also known as closures).
Consider the following example of an interface and the SavePerson() function that uses it:
// Saver persists the supplied bytestype Saver interface { Save(data []byte) error}// SavePerson will validate and persist the supplied personfunc SavePerson(person ...Read now
Unlock full access