4 ms·
One of the techniques to mitigate that problem specifically in Go is to create interfaces for everything. For example, instead of calling the datastore directl
by jamra 11y ago
One of the techniques to mitigate that problem specifically in Go is to create interfaces for everything. For example, instead of calling the datastore directly, create an interface with only the methods you need. Then, if you need to swap out your data store, you do so from the implementation of the interface, not having to change the code your business logic runs in.
- Jabbles 11y agoHow is that simpler than writing a package that replaces the datastore, then changing your imports?
- jamra 11y agoIf that feels simple to you, knock yourself out. I believe this is way simpler. Using interfaces will coral your datastore code into one location. Then, you only need to change that code in a very modular way. Heck, give the job to a friend and go for a walk. You can review the changes he made later without worrying that he crossed your routes up. Heck, you can even run your tests (same tests as before since you are using an interface) against your new datastore.