91-9990449935 0120-4256464 |
Command PatternA Command Pattern says that "encapsulate a request under an object as a command and pass it to invoker object. Invoker object looks for the appropriate object which can handle this command and pass the command to the corresponding object and that object executes the command". It is also known as Action or Transaction. Advantage of command pattern
Usage of command pattern:It is used:
Example of command patternLet's understand the example of adapter design pattern by the above UML diagram. UML for command pattern:These are the following participants of the Command Design pattern:
Implementation of above UML:Step 1Create a ActionListernerCommand interface that will act as a Command. Step 2Create a Document class that will act as a Receiver. File: Document.java
Step 3Create a ActionOpen class that will act as an ConcreteCommand. File: ActionOpen.java
Step 4Create a ActionSave class that will act as an ConcreteCommand. File: AdapterPatternDemo.java
Step 5Create a MenuOptions class that will act as an Invoker. File: ActionSave.java
Step 6Create a CommanPatternClient class that will act as a Client. File: AdapterPatternDemo.java
Output
Next TopicInterpreter Design Pattern in Java
|