[[#wd Lookup TitleRecipe29 ]]

Overview

This recipe discusses the issues in deciding whether to reuse existing renderers or to introduce a new one. Since this is not a question where you can decide on hard facts it also involves taste and is ultimately based on good judgement.

In the following we try to outline the basic line of thoughts you should consider when you have to decide about a new class.

Preconditions

Steps to do:

  1. First of all: Try to reuse existing renderers, that's why they're here!!

    So based on your knowledge, go through the list of the existing renderers and try them out. Maybe you don't know all that deep or you can combine several toghether to achieve the functionality and presentation you wish.

    Caveat: With HTML-Templates you can virtually do everything needed, but it is not always the most performant solution. HTML-Templates are great in defining layouts (fixed tables) or in providing some snippets with dynamic data.

    Beware of flag setting mania, too much conditional rendering is as bad as too much conditional code. Try to use polymorphism instead. Thats why the page configurations have some sort of inheritance.

    There are several results possible regarding your first step.



  2. If the result of your second step is that you have to build something new, then you have to decide several things:

  3. The technical implementation of a new Renderer is quite simple. You have to derive a subclass of Renderer. You have to implement the Method RenderAll and call the Macro RegisterRenderer('ClassName').
    If you want to use the new Renderer with an alias, you can define one in the Config.any file of the Server.
    Sample:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"class MyNewRenderer : public Renderer {"
    		"public:"
    		"	MyNewRenderer(const char *name);"
    		"	~MyNewRenderer();"
    		" "
    		"	virtual void RenderAll(ostream &reply, Context &c, const ROAnything &config);"
    		"};"
    		" "
    		"//---- MyNewRenderer ----------------------------------------------------------------"
    		" "
    		"RegisterRenderer(MyNewRenderer);"
    		" "
    		"MyNewRenderer::MyNewRenderer(const char *name) : Renderer(name) { }"
    		" "
    		"MyNewRenderer::~MyNewRenderer() { }"
    		" "
    		"void MyNewRenderer::RenderAll(ostream &reply, Context &c, const ROAnything &config)"
    		"{"
    		"	StartTrace(MyNewRenderer.RenderAll);"
    		"	// do some fancy stuff here"
    		"	..."
    		"}"
    	}
    }]]
    

Remarks

Glossary

Related Topics