8: Boundaries
Practices & techniques to keep the boundaries of our software clean when integrating with third-party packages and APIs.
Using Third-Party Code
There is a natural tension between the provider of an interface and the user.
Providers strive for broad applicability so they can appeal to a wide audience.
Users, want an interface focused to their particular needs.
This tension can cause problems at the boundaries of our systems.
Exploring & Learning Boundaries
Third-Party code helps us get more functionality delivered in less time.
Where do we start when we want to utilize a third-party package?
Learning & integrating third-party code is hard.
While it's not our job to test the third-party code, it may be in our best interest to write tests for the code we use.
Use Learning Tests
Instead of experimenting and trying third-party code in our production code, we could write some tests to explore our understanding of the third-party code.
We call the third-party code (API) as we expect to use it in our application.
These are controlled experiments that check our understanding of an API.
Learning Tests are Better Than Free
Learning tests are an easy, isolated way to gain knowledge.
They have a positive return on investment: the same tests are used to verify behavior during upgrades.
A clean boundary should be supported by a set of of outbound tests that exercise the interface in the same way Production code does.
Without these test, we may be tempted to stay with an old version longer than we should.
Clean Boundaries
Good software designs accommodate change without huge investments & rework.
Code at the boundaries needs clear separation & tests that define expectations.
We should avoid letting too much of our code know about the particulars of the third-party.
It's better to depend on something you control that on something you don't, lest it end up controlling you.
Manage third-party boundaries by having very few places in the code that refer to them. (i.e. use Wrappers or Adapters)
Last updated