I’m designing GUI (graphical user interface) system for a game engine (C++).
Idea is to create a heirarchy of GUI controllers like Focusable, Hoverable, Dragable etc. Every GUI component can attach multiple controllers, they modify component’s behaviour.
I think it gives flexible system and protects from code duplication. Different instances of the same GUI class can have different complex behaviours (may be, even change it dynamically), so this approach looks practical.
The other choice is to add focused, hovered, dragged etc. flags in the base GUI component class. It looks like overhead and not that flexible.
Another solution is to use Decorator pattern and wrap objects with FocusDecorator, HoverDecorator etc. Maintaining such system looks a bit harder.
Question: What are pitfalls in my solution? May be you have seen a better approaches in GUI systems? What are the best ways of implementing such flexible complex system?
Your solution is quite good, to be honest, I think it is exactly what the Decorator design pattern is about, however in C++ you have better implementation techniques at hand. You can easily use policy based design to create GUI component template class and add component behaviour trait classes as its arguments and then inherit from the arguments.