November 2018
Intermediate to advanced
346 pages
8h 12m
English
Before we dive too deep into constructor injection, we should spend a moment to talk about duck typing.
We have previously mentioned Go's support for implicit interfaces and how we can leverage it to perform dependency inversion and decouple objects. To those of you familiar with Python or Ruby, this may have felt like duck typing. For everyone else, what is duck typing? It's described as follows:
If it looks like a duck, and it quacks like a duck, then it is a duck
Or, put more technically:
At runtime, dynamically determine an object's suitability based only on the parts of that object that are accessed
Let's look at a Go example to see if it supports duck typing:
type Talker interface { Speak() string Shout ...
Read now
Unlock full access