This content has been marked as final. Show 7 replies
I think you have got some misunderstanding for property change listener. As per java docs, it is intended for beans. Whenever a bean changes its "bound" property, its propertyChange event gets fired.
yes, you are right
so that, we can adapt observer pattern by the usage of property change listener as well ?
A observer can observer the changes of the model. so do property change listener."Observer" is a design pattern in which an "Observer" is notified when changes occur to a "subject".
Beans with property change listeners are one example of a usage of this pattern.
Here the bean is the "subject" and each registered PropertyChangeListener is an "observer".
The difference between the propertyChangeListener and the Observer - Observable pattern is one of instantiation. The propertyChangeListner is an implementation of the observer pattern.
The observer - observable pattern is an abstract description of a problem - solution pair, the propertyChangeListner and eventListners etc. are all concrete implementations of this pattern.
- hope this helps.
Thanks , I always doubt that.
so, now i can confirm property change listener is "one" of the implementation of Observer pattern.
@aragon28 property change listener IS a form of observer but a 'loose' implementation. I never liked the implementation because setting up listeners and state change callbacks are based on text strings. Java makes even a worse implementation of this by not making the properties some kind constant, so for you to know what is happening and when is happening, troubleshooting can be a nightmare.
However, the other implementation of the pattern is interface based, such as the one you see in ActionListener and others in the awt, swing event/notification model. It is in my opinion a true observer pattern because looking at the subject(and in some cases the observer), you can tell what kind of events are supposed to happen and you can trace back easily when something is happening and from where it is getting called.
My last thought: I HATE PROPERTY CHANGE. Use the ones provided by frameworks you may need to use, but never use them for your own implementation of the pattern.
Please don't post in threads that are long dead and don't hijack other threads. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.
I'm locking this thread now.