struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anders K. Olsen" <>
Subject Re: Bean philosophy
Date Wed, 30 May 2001 15:31:11 GMT
----- Original Message ----- 
From: "Jonas Björnerstedt" <>
To: <>
Sent: Wednesday, May 30, 2001 4:55 PM
Subject: Bean philosophy

> 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?

In a Been, you can use a Hashtable to save your attributes, but you don't have to use a Hashtable.
I normaly don't. Because I know which attributes to expect, I implement these as fields in
the Bean, and save the values in these. I know that a Hashtable has an expected constant-time
on the get and put operations, but it is only expected time. With fields, I know that I have
a constant-time operations, besides I'm sure that Java won't have to do some bookkeeping behind
my back to insure the proper working of a Hashtable.

Besides that, you can do a lot of other interesting stuff in the get/set methods, like accessing
other objects, if you don't want to store the attributes in your Been.

I have also been programming Perl, and I know that Hashtables are a nice thing. But remember,
that a Java class is a proper class, and not just a hashtable in desguise.

But of course there are situations, where what you propose is very usefull.

View raw message