By moving the interface to the application-side (application.go
), you can still set the implementation-specific configuration details when you instantiate your library structs. If the interface was implemented on the library-side then you would need to provide:
type DB interface {
Get([]byte) ([]byte, error)
Put([]byte, []byte) error
CacheSize() int
SetCacheSize(int)
TurboMode() bool
SetTurboMode(bool)
}
The extra configuration functions are implementation specific. The generalization of DBs occurs on the application-side (not the library-side) so it makes more sense to only specify the interface required by the application on the application-side.