I am building a common interface for several different backends that are shared libs loaded at runtime dependend on the used platform. It looks basically like the code below. My problem is, that while 90% of the functions of all backends are the same (just different implementations but same purpose) some of them have features that are not available to other platforms at all.
If I had a wrapper function for all features than they would run into the void for backends that do not support them which I want to avoid. I also don't like the idea of having implementations of backend functions that just return errors.
What would be a good way to have a generic common interface while still being able to call functions specific to a backend if the user wants to limit his application to that platform?
class CommonInterface
{
void DoA(); // Calls InternalDoA() of loaded backend
void DoB(); // Calls InternalDoB() of loaded backend
void DoC(); // Calls InternalDoC() of loaded backend ???
};
class BackendOne
{
void InternalDoA();
void InternalDoB();
// DoC does not exist!
};
class BackendTwo
{
void InternalDoA();
void InternalDoB();
void InternalDoC();
};
Thanks a lot in advance!
void Foo()
is a black hole of "do something" with no real context. If that's the case, what's the problem withvoid BackendOne::InternalDoC(){}
? Otherwise, what are the preconditions and postconditions ofCommonInterface
s methods?BackendOne::InternalDoC
because it simply cannot do C due to hardware limitations. I am not sure what you mean by pre- and postconditions?CommonInterface
. It might be that you can just ignore the absence of C, or that you can fallback to something involving A and B, or you split the interface intoCommon
andCPossible
. Preconditions are anything that must be true before you call a function. Postconditions are anything the function promises are true after you call it.