On Dec 5, 10:51 pm, "Michael Lee" <[EMAIL PROTECTED]> wrote: > RogerV - I briefly read over the code - IMO - Enum is more of > 'strategy pattern'..
The tutorial article (that I've now provided a link to) had dubbed this approach - based on the Java enum feature - to be an example of the "template method pattern". When I went to the wikipedia entry that that article linked, what is described there is what us OOP developers accomplish by use of abstract classes and abstract methods. We code a high level algorithm in one place and rely on subclass implementations of abstract methods to provide the specific behavior for the particular item(s) being operated on. (This OOP approach is not the only way to do this pattern, as the wikipedia entry cites using C++ templates as well. C++ template libraries permit things like collection class templates to be combined with iterator and memory management templates, etc.) Well, the Java enum approach relies on the fact that enum ordinals are effectively subclass instances of their enum class. Hence you can place abstract method declarations in the enum class and then have each enum ordinal provide an implementation of the abstract method(s). It basically just makes for a very concise and tidy way to implement this pattern - particularly where it's convenient to think of the enum ordinals as representing command tokens. In my particular case of the JFig parser, I needed to go an additional step by associating strings from the raw input to their respective ordinal "command token". Hence I added a static map object to the enum class that is initialized with name/value pairs - raw input string as a key and the value being the respective enum ordinal. Once again the Java enum class provided a very convenient means to set up this string binding association to "command token". --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/javaposse?hl=en -~----------~----~----~----~------~----~------~--~---
