Having just switched from Perl to Java web development, perhaps I am missing
something fundamental. Being new to the forum, I also don't know if this
issue has been discussed before. 

It strikes me as odd that in beans in general and ActionForm beans in
particular that properties are set by setXxx and getXxx methods.
Spontaneously you would think that a bean should have a get("name") and a
set("name", "value") to retreive or save attributes in a Hashtable in the
bean. 

Reusability is one of the nice things about beans. With the current design
however, if I want to retreive the properties set in a bean in a reusable
way, I have to go the roundabout way of using reflection. My question is: In
what sense is a bean more than than a Hashtable?

Here is a simple illustration of the problem. A common task I have is to
generate an SQL insert statement to save the properties of a bean. I could
for each different form have an Action class that goes through all the
getter methods to generate the SQL string. To make life simple, I derive all
my beans from a class that uses reflection to examine what fields the
derived class has, creating the SQL string in the toString method. From what
I understand, I could have used PropertyUtils instead.  

Given that beans work the way they do, this is a reasonable method. But why
do things the hard way? Why not let ActionForm implement an interface with
only a get(), a set() and an getPropertyNames() method? With a Hashtable,
you could also allow the set method to add a property to the bean, something
I would find very useful. 

Perhaps I have spent too much time with Perl, but to me it seems like there
is too much structure here. In looking through the literature, I have not
found any discussion of this question. 

Jonas 

Reply via email to