I am developing a visual editor for an entity component system. The editor must be able to modify the members of differents components subtypes, so we have a specific window for each component subtype.
The problem is we can't modify the components to implement a polymorphic method to display the correct window since it's a extern library. So what would be a appropriate design to avoid this:
void edit(Component component) {
if (component instanceOf Position) {
new PositionEditorWindow((Position) component).display();
} else if (component instanceOf Velocity) {
new VelocityEditorWindow((Velocity) component).display();
} else if ...
}
(Separate comment: if we can modify the components, does it makes any sense to add a polymorphic method with editor logic to a component? I was thinking a visitor has more sense)