Command mode practice

Source: Internet
Author: User

Command mode practice

Topic

ArticleA simple shell library is used to describe a practical application of the command mode.

How to use shell Library

Before starting, let's take a look at how to use this shell library. The solution structure is shown in Figure 1-1)

 

Figure 1-1 Solution

The figure shows that the shell library is very simple. The icommand interface defines only one execute method. For details about the signature of this method, seeCodeListing 1-1.

Code List 1-1 

///   <Summary> Run the command and return the command execution result. </Summary>
///   <Param name = "ARGs"> Command to be executed </Param>
///   <Param name = "executemessage"> Command Execution result </Param>
Void Execute ( String [] ARGs, Ref   String Executemessage );

 

The command project contains specific classes that implement the icommand interface. See Code List 1-2

Code List 1-2

Public   Class Addusercommand: icommand
{
Public   Void Execute ( String [] ARGs, Ref   String Executemessage)
{
If (ARGs. Length ! =   3   | Share. ishasanyspace (ARGs ))
{
Executemessage =   " The adduser command parameter is incorrect! Format: adduser Username Password " ;
Return ;
}
String Username = ARGs [ 1 ];
String Password = ARGs [ 2 ];
Bllfactory. bllfactory. getinstance (). User. adduser (username, password );
Executemessage =   String . Format ( " User {0} added successfully! " , Username );
}
}

 

This class is created by the customer. In the code list 1-2, the addusercommand class implements the icommand interface. The specific implementation of the execute method is to call the adduser method of the bll layer to complete the operation of Adding users.

 

 

 

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.