I am currently working on a wrapper project which shall wrapp C# SDK functions with the help of C++/CLI to C++ unmanaged native code.
After some time, my boss wanted me to create setters for all "targets"(the context doesn't matter). "Targets" is in the C# SDK a interface/enum. Now, every target is grouped into a specific class of target. For example a OnePlus 5T
smartphone is in the group of Smartphones
which again is in the group of Device
. I need to create setters for a bunch of Smartphones
and other targets. Now, I am not able to group them, because each target has specific functions that it supports. For example OnePlus 5T
has a function which returns me it's RAM Size.
Now the problem is, in my code, I have to create for each target functions setters/getters. That means I end up with 30/40 setter/getter which I dont want. What if I need to change up something later? That would cost a lot of time.
Here some example code:
class __declspec(dllexport) IExample
{
public:
virtual void SetTargetAsiPhone5s() = 0;
virtual void SetTargetAsiPhone6s() = 0;
virtual void SetTargetAsiPhone7s() = 0;
virtual void SetTargetAsiPhone8s() = 0;
virtual void SetTargetAsiPhone9s() = 0;
virtual void SetTargetAsiPhone10s() = 0;
virtual void SetTargetAsiPhone11s() = 0;
virtual void SetTargetAsiPhone12s() = 0;
virtual void SetTargetAsiPhone13s() = 0;
virtual void SetTargetAsiPhone14s() = 0;
virtual void SetTargetAsiPhone15s() = 0;
virtual void SetTargetAsiPhone16s() = 0;
virtual void SetTargetAsiPhone17s() = 0;
virtual void SetTargetAsiPhone18s() = 0;
};
}
class Example : virtual public IExample
{
public:
void SetTargetAsiPhone5s();
void SetTargetAsiPhone6s();
void SetTargetAsiPhone7s();
void SetTargetAsiPhone8s();
void SetTargetAsiPhone9s();
void SetTargetAsiPhone10s();
void SetTargetAsiPhone11s();
void SetTargetAsiPhone12s();
void SetTargetAsiPhone13s();
void SetTargetAsiPhone14s();
void SetTargetAsiPhone15s();
void SetTargetAsiPhone16s();
void SetTargetAsiPhone17s();
void SetTargetAsiPhone18s();
private:
msclr::gcroot<ExampleManaged^ > m_ExampleManaged;
};
}
The class Example
uses a managed class ExampleManaged
which contains all Setters/Getters again. That managed class contains another managed class ExampleTargetsManaged
which contains again all Setters/Getters but also their real implementation.
Now, is there a way to reduce this workflow? I feel like I have to rewrite a lot of code and I'm writing bad structured code if I leave everything like it is. I could use instead of ExampleTargetsManaged
class a interface which ExampleManaged
inherits from. That would simplify the workflow atleast a bit I guess.
Comments
Post a Comment