A while ago I was asked this question when discussing our project’s architecture. I want to share my answer publicly, because it’s a subject that I encounter often.
I assume the idea is to decouple as much as possible, but understanding that as soon as you pick a piece of technology, you are coupled to it.
With any decoupling there are trade-offs. With any trade-off you have to decide if the benefit is worth the cost. In some cases it may be worth it to isolate the coupling. For example, we choose a third party library
MegaPayments2 to handle payments. We are essentially coupled to this technology choice. But it wouldn’t cost us much to isolate that dependency. Instead of sprinkling calls to
MegaPayments2 all over our project, we can create a wrapper class,
Payments, which delegates to
MegaPayments2 internally. Now
Payments is sprinkled throughout our system but the cost of change is now much lower. Maybe
MegaPayments2 becomes obsolete and we want to change to
UltraPayments3. We only have to do that in one place.
You may hear decoupling discussed as something that’s always good no matter what. But consider the trade-offs. When deciding if you should decouple, ask yourself these questions:
- How likely is it that this will change?
- How easy would it be to introduce a boundary to keep this isolated?
- Do we get any other benefits by introducing a boundary that we own? (e.g. a nicer API?)
With the above questions in mind, you can then ask yourself:
Should we decouple from python? No.
Should we decouple from our specific version of python? It depends…
Should we decouple from this third-party library? Probably yes.
Decoupling is a tool, like any other. Use it wisely.