MxUI/MUI

polymorphic uniface -- ideas / opinions wanted

AlexSkillen opened this issue · 3 comments

Would it be useful to define a uniface base class that is non-templated, and contains virtual member functions? Then the templated uniface inherits from the base class. This would allow polymorphism, like so:

Interface* inf = 0;
 
if (dim==1)
        inf = new uniface<config1d> ();
else if (dim==2)
        inf = new uniface<config2d> ();
 else if (dim==3)
        inf = new uniface<config3d> ();

inf->push(...)
inf->commit(...)    //works independent of interface dimension

We would perhaps need a constructor on point that takes three arguments so a 1D interface can always accept a point at (x, 0, 0) for instance. And the samplers would similarly need an abstract base class.

Not sure if this would be useful, or not.

The alternative for a generic dimensional code seems to be to have inf1d, inf2d and inf3d pointers and wrap everything MUI related in if(dim=1), etc. which seems messy.

Hi,

Yes definitely useful I think and a neat way to do things, it's also clear that the current design of either relying on specialism or templates is fairly messy, both in the mui.h file itself and also as a barrier to understanding how to use the code.

This suggestion could be rolled up into a larger piece of work to look at how to best create a single apparent interface class whilst actively discouraging the use of the specialism approach in future versions of the library/demo cases.

If not present already I would also consider a factory object for Interface that takes dimension as an argument. This will avoid code duplication for the cases in your listing.

GenericInterface might be a name worth considering.

Nitpicking: we might need an example without new. I think in C++11 and later they frown upon manual memory manipulation like this.

I'm going to close this issue for now as generally usage seems to have settled around the templated variant of the uniface class, this would represent a hybrid sort of approach in some ways, we can revisit in the future if needs be.