![]() That object will be used to execute the action later. When concrete commands are instantiated by a client (your main() ?), a reference to a receiver object is stored.Concrete commands are classes that implement this interface : optionAction() is overridden to define the actions that shall be executed for a specific command.The most important method here is optionAction() (corresponds to the execute() method of the pattern). A command interface defines the methods related to a menu option (i.e.Note: This will always be invoked from command prompt. Other than writing this in the itemAction method, any better way to design this ? ![]() Instead of adding to a list in register class, how about having the link between optionTitle and class info in an xml file or something ?Īnd I'll have submenus as well. With my solution also, if I want to add a new option, I would need to register each option in a list, implement the class etc. Is there any better way to design this ? Any design patterns that I can bring in ? My priority is good design. Otherwise I can use reflection/annotation to get the all the classes which implement this interface and show the menu -> This might be an overkill. Option selection would call the action of that particular class. Then my main program would iterate over this classes and shows the menu. I can have a class which where each option is registered. So each Option in the menu would implement this interface and write its action & title. Have an interface say IOption with methods like optionTitle, optionAction. Some options might show a submenu as well. I need to design this such that I should be able to add new options easily. Each option selection performs some independent operation say executing a script or performing some db operation, for example: 1 option1title I am trying to create a java console program which displays a Menu with few options.
0 Comments
Leave a Reply. |