November 2018
Intermediate to advanced
346 pages
8h 12m
English
Typically, when discussing OCP, the examples are littered with abstract classes, inheritance, virtual functions, and all kinds of things that Go doesn't have. Or does it?
What is an abstract class really? What is it actually trying to achieve?
It's trying to provide a place for code that is shared between several implementations. We can do that in Go—it's called composition. You can see it at work in the following code:
type rowConverter struct {}// populate the supplied Person from *sql.Row or *sql.Rows objectfunc (d *rowConverter) populate(in *Person, scan func(dest ...interface{}) error) error { return scan(in.Name, in.Email)}type LoadPerson struct { // compose the row converter into this loader rowConverter ...Read now
Unlock full access