Hi Gregg,
Sorry 4 late reply. Was relaxing a bit. I was not clear last time. This time i will try 2 b clear.
So is the Observable pattern that you mention something that has to be used explicitly along with Action Patterns? Or does Action Patterns subclass or implement Observable patterns and you can just use them that way?
I will just say few stuff. One can say, Observer == listener pattern. In short, if one uses Listeners in coding then we can say that he has used "Observer" pattern. When we design systems, we distribute the responsibilities among different classes like Managers, general clasees, Utility classes, etc.. and expect that they will on their own communicate with each other thru event notification mechanism. (And we r dammn sure about their behaviour cause they r not bloody egoist humans.) Now the classes which provide service (can be any class) should notify interested clients thru event notification. AbstractAction does this thru foll. API :-
1. addPropertyChangeListener(PropertyChangeListener)
2. removePropertyChangeListener(PropertyChangeListener)
and other related methods like getPropertyChangeListeners
When we pass Action to JButton or JMenu it calls it's setAction method which adds a property change listener if not added and configures it's properties according to the passed in action. (See the AbstractButton.java src code)
AbstractAction has getValue() putValue() methods. If any client puts any property (can be a standard defined in Action interface or any custom property) by putValue() then the AbstractAction fires a property describing that key-value. Now the resgietsred clients r the buttons and menu items or any other components like status bar fields. They quickly update their properties from the propertyChangeEvent. The code to do this is naturally in parent AbstractButton class. This class updates itself for the known properties defined in Action interface (like NAME, SMALL_ICON, etc..). So is achieved synchronization. One point to b noted is that :- Although the synchronization of buttons and menu items properties is automatic for the developer (cause Sun guys have done it 4 us in AbstractButton) there can be other components where the actions should be used e.g. Status bar field. In status bar any action can come cause the user can customize the status bar components thru customization if provided. So it's better to write StatusBarField component which will have almost API like AbstractButton like constructor accepting Action (same as JButton or menu item), setAction, and configurePropertiesFromAction etc.. Also not all the status bar fields should accept Action e.g. the field used for displying description has nothing 2 do with Actions. So the designer should design accordingly.
I have read on Observable patterns before, the problem is that all the examples I see don't introduce examples like you stated. So it is hard for me to take them over to a SWING example.
Actually i haven't read such examples from any book. I just try to study the existing designs in general life as well as in computing. There r lots of interesting examples. e.g. regarding the computing design. One more example about the "Observer" pattern would be Client-server chat. Instead of two clients constantly asking the server whether there is any message from other chatters (and many a times get upset) while the chatter logs in it should register with the server and any chatter just sends message to sever and that server will have handles of all the chatters and will notify all the other chatters. I have heard from my friend that some messangers constantly (in while(true) loop) queries server about other chatter's message etc. God bless such designers
About the example in general life. U know i never give my company's mail id to anybody (or if i give i also give one more default mail id as fallback) the reason being that by doing so i am exposing the internal details i.e. the company name (not following the "data encapsulation" design principle) . When i will join other company all my friends now will have to update their Address book just because i have joined a new company. Had that mail id from say yahoo then that will work till the rest of my life.
If you know of a simple SWING example that implements that patterns you described, could you provide me a link?
I don;t have any links. But i will HIGHLY RECOMMEND the
Core JFC by Kim Topley. This is the best book on swing. The author has more than 30 yrs experience in GUI building/designing. Study carefully how he approaches the solution of any prob. He approach is the best, slowly by slowly step by step.
Best Wishes,
Ashish