Simplify construction of nodes from server
Yet another idea that I am having is to do the trick of the server and the Params objects, directly in the Class objects. That is, remove this layer of having to create the params for then creating the object.
Is there any technical reason, i.e. non-historical reason, that prevents us to make constructors such as
struct ParamsA : public ParamsBase
{
Scalar field_1;
int field_2;
}
class SensorA : public SensorBase
{
public:
SensorA(ParamsServer _server) : SensorBase(_server)
{
params_a_.field_1 = _server.getParam<Scalar>(_unique_name + "/field_1");
params_a_.field_2 = _server.getParam<int> (_unique_name + "/field_2");
}
protected:
ParamsA params_a_;
}
Would it be interesting? I mean, would this be easier from the developer standpoint than what we have now? Of course, this would SUBSTITUTE the other approach through the constructors of ParamsA : ParamsBase
.
For me, the advantage is that now the ParamsXx
structs are mere structs with no methods at all, which makes them really easy objects. And the whole work is left for the constructor, which is quite easy to understand.