I have the following design request for a visual editing tool written in C++:
- be able to define a template object (assign image, edit default rotation/scale, edit default property values)
- be able to place instances of template object in view
- be able to make changes to template object (eg different image, change rotation, scale, property values) with all instances using the new values immediately or after clicking "Apply"
- Exception: if rotation, scale or any property value has been modified (overridden) at the instance, it should no longer take that value from its template!
What are good design choices for implementing such a template-instance relationship in C++ with the additional condition of instances being able to override template values? Is there a design pattern for that?
I came up with a few ideas but none strike me as the way to go. For example, I could have a TemplateObject class and a TemplateObjectInstance class. Through a 1-to-many relationship they "know" each other and for example, instances could check if a property is overridden locally (entry in TemplateObjectInstance's properties dictionary exists) and if not, tries to get the value from its parenting TemplateObject properties dictionary instead. Is that a solution that would work well enough?
Note: this question is not about C++ Templates.