I work for a company in software research department. We use algorithms from our real software and wrap them so that we can use them for prototyping. Every time an algorithm interface changes, we need to adapt our wrappers respectively.
Recently all algorithms have been refactored in such a manner that instead of accepting many different inputs and returning outputs via referenced parameters, they now accept one input data container and one output data container (the latter is passed by reference). Algorithm interface is limited to a static function call like that:
class MyAlgorithm{
static bool calculate(MyAlgorithmInput input, MyAlgorithmOutput &output);
}
This is actually a very powerful design, though I have never seen it in a C++ programming environment before. Changes in the number of parameters and their data types are now encapsulated and they don’t change the algorithm callback.
In the latest algorithm which I have developed I used the same scheme. Now I want to know if this is a popular design pattern and what it is called.
5
This is actually a very powerful design, though I have never seen it
in a C++ programming environment
I think the word powerful is open to interpretation, and really depends on perspective, agreeing with Kilian Foth comment, in what he calls an anti-pattern.
Most C++ projects you will see are likely open sourced, or open in one way or another, thus licencing modules and code obfuscation techniques will be hard to come by.
After all, with the technique you described you will sacrifice to some degree meaningful IDE code assistance, which is used by a gross section of programmers.
This kind of wrapping makes things more obfuscated, and I am guessing part of the motivation to do so may actually be protection of Intellectual property, notwithstanding the slight performance impact due to the extra stack operations.
On the other hand it depends on the programming language and its idiosyncrasies:
In JavaScript for instance I use such a ‘pattern’ for instance to pass strings by reference.
In C++ it would make sense for additional parameter, type, sanity, pointer and memory bounds testing. As such it takes a page from managed code minus the application virtual machine. Please, correct me if I am wrong.
I could see this type of wrapping being employed frequently in game engine development. Is your company by any means involved in that field?
3