Java Command mode ~

Source: Internet
Author: User

The command pattern is a data-driven design pattern that belongs to the behavior pattern category. The request is wrapped as a command under an object and passed to the caller object. The caller object looks for the appropriate object that can handle this command, and passes the command to the appropriate object that executes the command.

Implementing an instance

In this example, an interface is created as a command- Order and a class is created as a Stock request. There are specific command classes BuyStock and SellStock implementation Order interfaces that will do the actual command processing. A class is created Broker as the caller object. It can receive and place orders.

BrokerObject uses command mode to identify which object and which command to execute according to the command type. CommandPatternDemoThis is a demo entry class that will use the Broker class to demonstrate the command pattern.

The implementation instance structure of the command pattern is as shown in-

Click on the link to view the details

Java Command mode ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.