Database interface for users - #24
Conversation
In the future this will allow to use other databases.
| func TestImplements(t *testing.T) { | ||
| var i interface{} = &UserDatabase{} | ||
| if _, ok := i.(database.UserDatabase); !ok { | ||
| t.Errorf("UserDatabase doesn't implement database.UserDatabase") | ||
| } |
There was a problem hiding this comment.
We can replace this whole thing with a compile-time check:
var_ database.UserDatabase= (*UserDatabase)(nil)There was a problem hiding this comment.
I've seen this in use, however in my opinion it directly contradicts
There is no explicit declaration of intent, no "implements" keyword.
Implicit interfaces decouple the definition of an interface from its implementation
The compile-time check adds this explicit declaration of intent. Placing it in tests allows to check can the type potentially be used as intended, rather than tying it to the interface. Furthermore, when a consumer is using the type, they will get that compile-time check anyways.
But this is just my opinion, if you prefer for me to change it, I'll be happy to oblige.
This change add an interface which can be implemented by various systems to store the data. This means that we won't have to always rely on SQL. It is up to implementation to return the correct information.
3c69342 to
0daf815CompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Ryan didn't want the shrug.
This change add an interface which can be implemented by various systems
to store the data. This means that we won't have to always rely on SQL.
It is up to implementation to return the correct information.