A large number of lines of code is not a measure of success.  Do not cut-and-paste to avoid a real solution.

For example:

public void setAttr1(String attr1)  
{
    decoratee.setAttr1(attr1);
}

public void setAttr2(String attr2)  
{
    decoratee.setAttr2(attr2);
}

:
:

public void setAttr20(String attr20)  
{
    decoratee.setAttr20(attr20);
}

:
:

// but there is more – all the getters!
public String getAttr1()  
{
    return decoratee.getAttr1();
}
:

The above example created code-bloat elsewhere when the methods were called.  So as a general policy, variables or methods that end in numbers should trigger an immediate code review and fix.  

A better alternative would be the following, adjusting the caller to loop through the attributes.

public static int MAX_ATTRIBUTES = 20;

public void setAttr(int attrNo, String attribute)  
{
    attributes.put(new Integer(attrNo), attribute);
}

public String getAttr(int attrNo)  
{
    return (String)attributes.get(new Integer(attrNo));
}

By simplifying to just two methods, extra work can be saved.  The range of parameters can be validated in one place.  Return values can be validated in one place.

blog comments powered by Disqus