Menus provide a classic example of the need for the command pattern. The developers who wrote the code for the JMenuItem class had no way of knowing what action you want should happen when you choose a menu-item option for lets say "save".
So the solution is to use polymorphism: make the name of the action fixed and let the implementation vary. For JMenuItem, the operation is actionPerformed(). When the user makes a choice, a JMenuItem object calls the actionPerformed() method of any object that has registered as a listener. Hope that helps, /stefan -----Ursprungligt meddelande----- Fr�n: jayaraman sureshkumar [mailto:[EMAIL PROTECTED]] Skickat: den 18 juni 2002 12:34 Till: JDJList �mne: [jdjlist] Command design pattern Hello, I need to know a simple example explaining the subject design pattern in a nut shell.. please help.. Thanks Suresh _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. To change your membership options, refer to: http://www.sys-con.com/java/list.cfm To change your membership options, refer to: http://www.sys-con.com/java/list.cfm
