There is no absolute rule to follow when determining whether formalized abstractions should be used (if abstractions are not already present). However, there are some hints, which are as follows:
- If you're writing code that can be used by more than one project: Interfacing with the underlying hardware should be done through an abstraction (the ADC driver and algorithm in the preceding section are examples of this). Otherwise, the code will be tied to the specific piece of hardware it was written for.
- If your code interacts with a vendor-specific API: Creating a light abstraction layer above it will reduce vendor lock-in. After interfaces are commonly used and set up, you'll start to gravitate toward ...