I'm currently using decorators to apply various modifications to a template prior to rendering it.
I'm unsure about my cache decorator, though, because it is currently able to break the chain of decorators and return a cached object as opposed to the original decorated object.
class Cache : Decorator
{
public String Render()
{
if(templateCache.IsCached('some_template_identifier'))
{
return templateCache.Get('some_template_identifier');
}
String renderedTemplate = Template.Render();
templateCache.Cache(renderedTemplate);
return renderedTemplate;
}
}
Is this bad practice? Should I always be returning the original decorated object or is it ok to break the flow like this and return a different object?