Improving the Design with Dynamic Interface

Now that we’ve reviewed the existing design with its duplicate conditional logic, let’s improve the design and eliminate the duplication with a dynamic interface.

A dynamic interface uses one or more function pointers to allow the implementation of a given function to be chosen at runtime. This single level of indirection provides runtime flexibility.[31] Function pointers are a powerful language feature that allow the caller of a function to avoid a compile or link-time dependency on a particular function.

Applying OCP and LSP

We can apply the Open Closed and the Liskov Substitution Principles to eliminate the redundant conditional logic. The design vision is illustrated in Figure 26, Extendable ...

Get Test Driven Development for Embedded C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.