The answer depends on that.
I see no reason to clutter up your base interface fill/get_fillable_instance/... if not every object needs to handle filling. You can, however, get away with just
struct slide_object { virtual void fill() {}
but it depends on whether you think fill should appear in the abstract class of the slide object. However, this should rarely be done unless the exception is exceptional.
Dynamic casting may be correct if you need to provide two different classes of objects (and no more than two), some of which are fillable, while others have nothing to do with fillability. In this case, it makes sense to have two sub-hierarchies and use dynamic casting where you need it.
I have successfully used this approach in some cases, and it is simple and easy to maintain if the sending logic is not scattered (i.e. there is only one or two places where you dynamically execute).
If you expect that you will have more actions with padding, then dynamic_cast is the wrong choice, as this will lead to
if (auto* p = dynamic_cast<fillable*>(x)) ... else if (auto* p = dynamic_cast<quxable*>(x)) ...
what is wrong. If you need it, then create a visitor template.
source share