views:

113

answers:

3

What exactly is the point of bound properties? To me they seem to be a less type-safe version of events using EventObjects - it seems a bit weak to be using string equality checking for event.getPropertyName().

Why would you use one over the other?

A: 

JavaBeans is a specification. It defines a bound property as that whose modification results in a notification being emitted, and a PropertyChangeEvent is the sanctioned notification entity.

So the putative JavaBeans-spec bean editor is supposed to listen for PropertyChangeEvents. Beyond the need to work with that spec, I wouldn't use it, myself.

Noel Ang
A: 

I think that JavaBeans specification was designed with generic object handling in mind. By example, putting a JavaBean in a IDE and using a visual property editor to configure it. In that case the IDE will use the general PropertyChangeEvent and so on.

Or if you want to copy equal named properties from a bean to another... it's another case of bean use (BeanUtils class).

But, if you plan to do specific things, as Noel Ang says I'd recommend strong-typing.

helios
+1  A: 

The whole point of Java Beans is that a system (GUI Builder, in particular) can examine a Java Bean and configure it without any previous knowledge of that component.

Although this is fairly cool, it's really only useful in this specific situation and these days annotations would work MUCH better.

So the reason they use bound properties was simply to support this drop-in GUI component technology, and I wouldn't really prefer it over events unless you need to support a reflective gui-building system.

Bill K