velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jon Stevens <>
Subject Re: ReferenceException
Date Mon, 02 Jul 2001 23:59:11 GMT
on 7/2/01 4:47 PM, "Lane Sharman" <> wrote:

> A class with public instance members have a role to play in
> applications, especially when the instance containing them is
> referenced by a secure and debugged referent.
> -lane

public instance members which are not static (or static final) is bad OO
design IMHO and unlike WebMacro, Velocity does a very good job of not
encouraging people to go down the wrong path of bad design. :-)

It is easy enough to get around this design choice in Velocity by simply
using a Hashtable and a better design for the Hyperlink class...

public class Hyperlink
    private Hashtable innerTable = new Hashtable();

    public String get(String name)
        return (String) innerTable.get(name);
    public void set(String name, String value)
        innerTable.put(name, value);

Then, in your code:

    hl.set("Label", "/site/section");

And in your template:


The advantage to this design is that you no longer have to modify the
Hyperlink class in order to add another "field", you don't have a bad OO
design in your class and the end result is very similar to what you already

On top of it, you have the ability to add more control over the assignment
of the variables. For example, you could have the set() method throw an
exception if a name already exists or do data validation on the items going
into the fields. This is something you wouldn't be able to do with straight
assignment of instance variables.



View raw message