From: Andy D. <an...@ma...> - 2004-08-25 15:09:48
|
On Tuesday 24 August 2004 09:33 pm, Oliver Hutchison wrote: > The most robust/encapsulation safe solution would be this: > > Object oldValue = beanWrapper.getPropertyValue(aspect) > beanWrapper.setPropertyValue(aspect, newValue); > if (! ObjectUtils.nullSafeEquals(beanWrapper.getPropertyValue(aspect), > oldValue) { > fireValueChanged(aspect); > } > The reason this might break encapsulation is because it assumes all properties on all beans must work exactly the same. The assumption the above code makes is: a bean will only ever set a property value to the very same value I passed to the setter. The bean will not perform any additional processing on the value and it will not end up setting an alternate value instead of the one I passed in. Granted, this is true in most cases - but I'm sure there will also be cases where the value you pass to a setter is not the value that ends up in the property (for example, a setter may massage the value or wrap it in some other object instance before setting). Having said all this, I still think there is value in the above solution as long as there is a way to override it. That is why I like your idea below... > Perhaps as a compromise we could do the above if the bean does not > implement PropertyChangePublisher and keep the current implementation if > it does. I agree that it would be nice not to change my domain objects. Having the option to alter behavior is always nice, and having a default that works in most cases is doubly nice. |