Sunday, June 3, 2018

Just one library with different immplementations? d-pointer desing pattern to the rescue

I'm developing a library based on Qt to access the Sense HAT add-on for Raspberry Pi. It's based on ideas and code from Qt's experimental module and from this other library. The ultimate goal is to provide a library that can be used with either the actual hardware or the Sense Emulator without any code changes to the program using it.
So the application using the library will include just the header(s) file(s) with the function declarations it provides, and will reference the required library (for hardware or software access) in its project file (.pro). No more changes.

But how to achieve such goal? Well, Qt framework has been doing this long long ago: using the d-pointer design pattern. That's why Qt source code is full of Q_D and Q_Q macros: the implementation details of a library may be hidden from its users and changes to the implementation can be made to a library without breaking binary compatibility.

No comments:

Post a Comment