开发者

What's a good C++ code design for a one Template Object -> multiple Instance Objects architecture?

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.


I don't see why this needs to be complicated. Unless there are additional constraints you're not letting us know about...

class RealItem;

class TemplateItem 
{
    //data members
public:
    //set properties and such
    RealItem MakeRealItem() const; //Generates a RealItem from this template.
};

class RealItem
{
    //etc...
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜