CN112667324A - Method and device for calling command class in command mode - Google Patents

Method and device for calling command class in command mode Download PDF

Info

Publication number
CN112667324A
CN112667324A CN202011612880.XA CN202011612880A CN112667324A CN 112667324 A CN112667324 A CN 112667324A CN 202011612880 A CN202011612880 A CN 202011612880A CN 112667324 A CN112667324 A CN 112667324A
Authority
CN
China
Prior art keywords
command
class
command class
type
callable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202011612880.XA
Other languages
Chinese (zh)
Other versions
CN112667324B (en
Inventor
吴超
戴志强
金刚
赵严
姚毅
杨艺
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Luster LightTech Co Ltd
Suzhou Luster Vision Intelligent Device Co Ltd
Suzhou Lingyunguang Industrial Intelligent Technology Co Ltd
Original Assignee
Luster LightTech Co Ltd
Suzhou Luster Vision Intelligent Device Co Ltd
Suzhou Lingyunguang Industrial Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Luster LightTech Co Ltd, Suzhou Luster Vision Intelligent Device Co Ltd, Suzhou Lingyunguang Industrial Intelligent Technology Co Ltd filed Critical Luster LightTech Co Ltd
Priority to CN202011612880.XA priority Critical patent/CN112667324B/en
Publication of CN112667324A publication Critical patent/CN112667324A/en
Application granted granted Critical
Publication of CN112667324B publication Critical patent/CN112667324B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The application provides a method for calling a command class in a command mode, which specifically comprises the following steps: adding parameters into a command class of an object-oriented computer program, and instantiating the command class; when the command class is successfully instantiated, constructing a command class object; receiving any type of callable object by calling the method of the command class object; and when the callable object of any type is successfully received, calling the successfully instantiated command class service interface to execute the request in the object-oriented computer program. The application also provides a device for calling the command class in the command mode. According to the method and the device, for any type of callable object, the setting of request processing can be completed only by using the same class template, and the command class provides a uniform command class service interface to complete the call of the request, so that the problem that the command class expands and is not converged due to the increase of the number of newly-built command classes is effectively solved, and the complexity of the system is reduced.

Description

Method and device for calling command class in command mode
Technical Field
The present application relates to the field of software architecture technologies, and in particular, to a method and an apparatus for calling a command class in a command mode.
Background
In the design of the software architecture, a programmer only cares whether a task is completed or not, and does not care which specific object executes the task, so that the 'behavior request' and 'behavior implementation' in the task can be decoupled by using the characteristics of a command mode in the software architecture. When a specific command class in the command mode needs to be newly added or adjusted when meeting the requirement change, the command mode characteristics can be utilized to add or delete the command class without influencing other classes on the basis of meeting the 'switching principle'. However, as the number of "requests for behavior" increases, the number of command classes required to encapsulate different "requests for behavior" also increases, resulting in command class bloating and non-convergence.
Disclosure of Invention
The application provides a method and a device for calling command classes in a command mode, which are used for solving the problems that in the prior art, the number of command classes is increased due to the fact that new command classes need to be redefined for different requests, and command class expansion is not converged.
In one aspect, the present application provides a method for calling a command class in a command mode, which specifically includes the following steps:
adding parameters into a command class of an object-oriented computer program, and instantiating the command class, wherein the parameters are the types of execution results requested in the object-oriented computer program, and the command class is a class capable of receiving any type of callable object;
after the command class is successfully instantiated, constructing a command class object, wherein the command class object is a variable defined by the command class;
receiving any type of callable object by calling the method of the command class object;
and when the callable object of any type is successfully received, calling the successfully instantiated command class service interface to execute the request in the object-oriented computer program.
In a preferred embodiment of the present application, adding a parameter to a command class of an object-oriented computer program, instantiating the command class, further comprises:
and when the command class is not successfully instantiated, adding the parameters to the command class of the object-oriented computer program again to instantiate the command class.
In a preferred embodiment of the present application, receiving any type of callable object by calling the method of the command class object further includes:
when the callable object of any type is not received successfully, the command class object is reconstructed, and the callable object of any type is received again by calling the method of the command class object.
In the preferred embodiment of the present application, the callable objects mainly include function objects, function pointers, functions, anonymous functions, non-constant member functions, and constant member functions.
In the above technical solution, the callable objects further include lambda expressions, and the command class hides the differences between the callable objects through the lambda expressions and assigns values to the member variables thereof; the type of the command class member variable is a Function, which is convenient to call when receiving a request. And the command class has a uniform command class service interface and can complete the execution of the request.
In a preferred embodiment of the present application, the command class receives any type of callable object in the same call form through a Function (Function) property, the command class maintains a constant (const) property and a right-value property or a left-value property of any type of parameter through a right-value reference property, and the command class receives any type of parameter through a variable template parameter.
In another aspect, the present application provides an apparatus for invoking a command class in a command mode, the apparatus comprising a processor configured to implement:
adding parameters into a command class of an object-oriented computer program, and instantiating the command class, wherein the parameters are the types of execution results requested in the object-oriented computer program, and the command class is a class capable of receiving any type of callable object;
after the command class is successfully instantiated, constructing a command class object, wherein the command class object is a variable defined by the command class;
receiving any type of callable object by calling the method of the command class object;
and when the callable object of any type is successfully received, calling the successfully instantiated command class service interface to execute the request in the object-oriented computer program.
Compared with the prior art, the method and the device for calling the command class in the command mode have the following beneficial effects:
(1) according to the method, the command classes are packaged, the member method in the packaged command classes can receive any type of callable objects, when a new request is added, the new command classes do not need to be redefined to meet the requirement, the command classes only need to be instantiated, and the callable objects are arranged in the command class objects to process the new request, so that the problem that the command classes expand and are not converged due to the fact that the number of the newly-built command classes is increased is effectively solved, and the complexity of the system is reduced.
(2) According to the method and the device, for any type of callable object, the setting of request processing can be completed only by using the same type template, and the command type adopts a unified command type service interface to complete the calling of the request, so that the complexity of the program is greatly reduced, and the program is more convenient to develop and maintain.
Drawings
In order to more clearly explain the technical solution of the present application, the drawings needed to be used in the embodiments will be briefly described below, and it is obvious to those skilled in the art that other drawings can be obtained according to the drawings without creative efforts.
FIG. 1 is a flow chart of a method for invoking command classes in a command mode according to the present application;
FIG. 2 is a flow chart of a method for solving command class inflation non-convergence by using GOF in the comparative example of the present application.
Detailed Description
To make the objects, embodiments and advantages of the present application clearer, the following description of exemplary embodiments of the present application will clearly and completely describe the exemplary embodiments of the present application with reference to the accompanying drawings in the exemplary embodiments of the present application, and it is to be understood that the described exemplary embodiments are only a part of the embodiments of the present application, and not all of the embodiments.
Thus, the following detailed description of the embodiments of the present application, presented in the accompanying drawings, is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
All other embodiments, which can be derived by a person skilled in the art from the exemplary embodiments described herein without inventive step, are intended to be within the scope of the claims appended hereto. In addition, while the disclosure herein has been presented in terms of one or more exemplary examples, it should be appreciated that aspects of the disclosure may be implemented solely as a complete embodiment.
It should be noted that the brief descriptions of the terms in the present application are only for the convenience of understanding the embodiments described below, and are not intended to limit the embodiments of the present application. These terms should be understood in their ordinary and customary meaning unless otherwise indicated.
In the design of a software architecture, close coupling relation between 'requests for behaviors' and 'implementation of behaviors' often exists, which is very disadvantageous to the expansion and maintenance of software functions, and GOF (abbreviation of 4 persons) proposes to adopt a command mode. The definition of the command schema is to encapsulate a request as an object so that different requests can be used to parameterize the client and to support request queuing or logging and to support operations to undo requests. The core meaning of adopting the command mode is to abstract the action to be executed, and to encapsulate the action into a command object, and the command object can be stored, recorded, processed, forwarded, and withdrawn. When certain operation needs to be recorded or cancelled, the command mode and the memo mode can be combined to realize the functions of command cancellation, command recovery and the like. As the number of requests increases, the number of specific command classes encapsulating the request also increases, so that the command classes expand and do not converge, the complexity of the software system is increased, and the command mode is the largest defect.
The following specifically describes an implementation of the present application in conjunction with the technical solutions of the present application.
Example 1
As shown in fig. 1, the present application provides a method for calling a command class in a command mode, which specifically includes the following steps:
s101, adding parameters into a command class of an object-oriented computer program, and instantiating the command class, wherein the parameters are execution result types requested in the object-oriented computer program, and the command class is a class capable of receiving any type of callable object;
s102, when the command class is successfully instantiated, constructing a command class object, wherein the command class object is a variable defined by the command class;
s103, receiving any type of callable object by calling the method of the command class object;
s104, when the callable object of any type is successfully received, calling the successfully instantiated command service interface, and executing the request in the object-oriented computer program.
In this embodiment 1, step S101 further includes:
and when the command class is not successfully instantiated, adding the parameters to the command class of the object-oriented computer program again to instantiate the command class.
In this embodiment 1, step S103 further includes:
when the callable object of any type is not received successfully, the command class object is reconstructed, and the callable object of any type is received again by calling the method of the command class object.
It should be noted that, in this embodiment 1, the callable objects mainly include Function objects, Function pointers, functions (functions), anonymous functions, non-constant member functions, and constant member functions.
In the above technical solution, the callable objects further include lambda expressions, and the command class hides the differences between the callable objects through the lambda expressions and assigns values to the member variables thereof; the type of the command class member variable is a Function, which is convenient to call when receiving a request. And the command class has a uniform command class service interface and can complete the execution of the request.
It should be particularly noted that, in this embodiment 1, the command class calls any type of callable object using the same call form through a Function (Function) property, the command class maintains a constant (const) property and a right value property or a left value property of any type of parameter through a right value reference property, and the command class receives any type of parameter through a variable template parameter.
Further, in this embodiment 1, the command class may also hide any form of the callable object through a lambda expression of the object-oriented computer program; providing the same pattern for each extended element using the package extension property of the object-oriented computer program; the correctness of the template instantiation type is checked in the compiling period by using the basic library type tracks developed by an object-oriented computer program. By utilizing the characteristics, the command class can be repackaged to receive any type of function object, and the problem of adaptation of any command class is solved.
Example 2
The application further provides an apparatus for invoking command classes in a command mode, the apparatus comprising a processor configured to implement:
adding parameters into a command class of an object-oriented computer program, and instantiating the command class, wherein the parameters are the types of execution results requested in the object-oriented computer program, and the command class is a class capable of receiving any type of callable object;
after the command class is successfully instantiated, constructing a command class object, wherein the command class object is a variable defined by the command class;
receiving any type of callable object by calling the method of the command class object;
and when the callable object of any type is successfully received, calling the successfully instantiated command class service interface to execute the request in the object-oriented computer program.
It should be particularly noted that, in embodiment 1 and embodiment 2 of the present application, for the repackaged command class, only a part of any callable object may be supported as the command class wrapper, for example: the encapsulated command class only supports Function objects, Function pointers, functions (functions), lambda expressions, etc., but does not support member Function types, etc., and the same is also applicable.
Comparative example
The GOF proposes a simple command without parameters and return values aiming at the problem that the command class is possibly expanded, a class template can be adopted to parameterize a Receiver of the command, specifically, a class template is defined, template parameters are instantiated by a Receiver, a Receiver object and an action are maintained in the class, and a pointer of the Receiver and a class member function pointer without parameters and return values in the Receiver class are required to be input when the command class object is constructed. Although continuous creation of command classes can be avoided to a certain extent, the method is only suitable for command classes without parameters and return values, has large limitation, and still cannot solve the problem that expansion and non-convergence of command classes caused by continuous creation of command classes for other command classes with return values or parameters.
As shown in fig. 2, the specific implementation steps of the GOF to solve the unconvergence of the command class inflation are as follows:
defining a class template;
using a Receiver as a parameter of class template instantiation;
judging whether the class template is successfully instantiated;
if the class template is successfully instantiated, constructing a command object;
the method comprises the steps that a command object is built and specifically comprises a first parameter and a second parameter, wherein the first parameter is input into a Receiver class object, and the second parameter is input into a member function of the Receiver class without parameters and return values;
judging whether the command object is successfully constructed;
if the command object is successfully constructed, calling an Execute method to Execute a request;
if the command object is not successfully constructed, returning to the step of reconstructing the command object;
and if the class template is not successfully instantiated, returning to the step of re-instantiating the class template.
The embodiments provided in the present application are only a few examples of the general concept of the present application, and do not limit the scope of the present application. Any other embodiments extended according to the scheme of the present application without inventive efforts will be within the scope of protection of the present application for a person skilled in the art.

Claims (10)

1. A method for calling command classes in a command mode is characterized by comprising the following steps:
adding parameters into a command class of an object-oriented computer program, and instantiating the command class, wherein the parameters are the types of execution results requested in the object-oriented computer program, and the command class is a class capable of receiving any type of callable object;
after the command class is successfully instantiated, constructing a command class object, wherein the command class object is a variable defined by the command class;
receiving any type of callable object by calling the method of the command class object;
and when the callable object of any type is successfully received, calling the successfully instantiated command class service interface to execute the request in the object-oriented computer program.
2. The method of claim 1, wherein adding parameters to a command class of an object-oriented computer program instantiates the command class, further comprising:
and when the command class is not successfully instantiated, adding the parameters to the command class of the object-oriented computer program again to instantiate the command class.
3. The method of claim 1, wherein receiving any type of callable object by calling the method of the command class object, further comprises:
when the callable object of any type is not received successfully, the command class object is reconstructed, and the callable object of any type is received again by calling the method of the command class object.
4. The method of claim 3,
the callable objects mainly comprise function objects, function pointers, functions, anonymous functions, non-constant member functions and constant member functions.
5. A method of invoking a command class in command mode according to claim 1 or 2,
the command class calls any type of callable object in the same calling mode through function characteristics, keeps constant attributes and right or left attributes of any type of parameters through right value reference characteristics, and receives any type of parameters through variable template parameters.
6. An apparatus for calling command classes in command mode, using a method for calling command classes in command mode according to any of claims 1-5,
the apparatus includes a processor configured to implement:
adding parameters into a command class of an object-oriented computer program, and instantiating the command class, wherein the parameters are the types of execution results requested in the object-oriented computer program, and the command class is a class capable of receiving any type of callable object;
after the command class is successfully instantiated, constructing a command class object, wherein the command class object is a variable defined by the command class;
receiving any type of callable object by calling the method of the command class object;
and when the callable object of any type is successfully received, calling the successfully instantiated command class service interface to execute the request in the object-oriented computer program.
7. The apparatus of claim 6, wherein the parameter is added to a command class of the object-oriented computer program, and the command class is instantiated, further comprising:
and when the command class is not successfully instantiated, adding the parameters to the command class of the object-oriented computer program again to instantiate the command class.
8. The apparatus of claim 6, wherein the method for calling the command class object receives any type of callable object, and further comprises:
when the callable object of any type is not received successfully, the command class object is reconstructed, and the callable object of any type is received again by calling the method of the command class object.
9. The apparatus for invoking command class in command mode as recited in claim 8,
the callable objects mainly comprise function objects, function pointers, functions, anonymous functions, non-constant member functions and constant member functions.
10. An apparatus for invoking command classes in command mode according to claim 6 or 7,
the command class calls any type of callable object in the same calling mode through function characteristics, keeps constant attributes and right or left attributes of any type of parameters through right value reference characteristics, and receives any type of parameters through variable template parameters.
CN202011612880.XA 2020-12-30 2020-12-30 Method and device for calling command class in command mode Active CN112667324B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011612880.XA CN112667324B (en) 2020-12-30 2020-12-30 Method and device for calling command class in command mode

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011612880.XA CN112667324B (en) 2020-12-30 2020-12-30 Method and device for calling command class in command mode

Publications (2)

Publication Number Publication Date
CN112667324A true CN112667324A (en) 2021-04-16
CN112667324B CN112667324B (en) 2023-12-05

Family

ID=75411178

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011612880.XA Active CN112667324B (en) 2020-12-30 2020-12-30 Method and device for calling command class in command mode

Country Status (1)

Country Link
CN (1) CN112667324B (en)

Citations (20)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO1994015275A1 (en) * 1992-12-23 1994-07-07 Taligent, Inc. Command system
US6032152A (en) * 1997-12-31 2000-02-29 Intel Corporation Object factory template
WO2002069147A1 (en) * 2001-02-23 2002-09-06 Appresso Spa Data linkage system
US20040264782A1 (en) * 2003-06-26 2004-12-30 International Business Machines Corporation System and method for object-oriented graphically integrated command shell
CN1740970A (en) * 2004-08-27 2006-03-01 微软公司 System and method for seamlessly comparing objects
US20070245036A1 (en) * 2006-03-03 2007-10-18 Khaled Fekih-Romdhane Illegal commands handling at the command decoder stage
CN101073057A (en) * 2003-10-24 2007-11-14 微软公司 Mechanism for providing extended functionality to command line instructions
CN102736910A (en) * 2011-05-11 2012-10-17 新奥特(北京)视频技术有限公司 Plugin-based general command interface definition method
CN103049306A (en) * 2011-09-12 2013-04-17 微软公司 Simulation of static members and parameterized constructors on an interface-based api
US20150234667A1 (en) * 2014-02-14 2015-08-20 Red Hat, Inc. Defining classes as singleton classes or non-singleton classes
CN105243018A (en) * 2015-10-24 2016-01-13 北京航空航天大学 Object-oriented class test data generation method
CN106528166A (en) * 2016-11-22 2017-03-22 郑州云海信息技术有限公司 Command line interface processing system and method
US20180357051A1 (en) * 2017-06-13 2018-12-13 Microsoft Technology Licensing, Llc Model binding for command line parsers
CN109683992A (en) * 2017-10-18 2019-04-26 北京京东尚科信息技术有限公司 Method and apparatus for managing object
CN110601880A (en) * 2019-09-02 2019-12-20 平安科技(深圳)有限公司 Cloud platform, service processing method, command interface and computer equipment
CN111221519A (en) * 2019-11-12 2020-06-02 广州银汉科技有限公司 Python-based CLI automatic export method
US20200174804A1 (en) * 2018-12-04 2020-06-04 Sap Se Graphical User Interface Command Pattern
CN111343221A (en) * 2018-12-18 2020-06-26 北京奇虎科技有限公司 Service processing method and device under command mode based on universal interface framework
CN111506307A (en) * 2020-04-10 2020-08-07 北京凌云光技术集团有限责任公司 Parameter chain-based subentry expansion method and system
EP3719643A1 (en) * 2019-04-03 2020-10-07 DreamWorks Animation LLC Extensible command pattern

Patent Citations (20)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO1994015275A1 (en) * 1992-12-23 1994-07-07 Taligent, Inc. Command system
US6032152A (en) * 1997-12-31 2000-02-29 Intel Corporation Object factory template
WO2002069147A1 (en) * 2001-02-23 2002-09-06 Appresso Spa Data linkage system
US20040264782A1 (en) * 2003-06-26 2004-12-30 International Business Machines Corporation System and method for object-oriented graphically integrated command shell
CN101073057A (en) * 2003-10-24 2007-11-14 微软公司 Mechanism for providing extended functionality to command line instructions
CN1740970A (en) * 2004-08-27 2006-03-01 微软公司 System and method for seamlessly comparing objects
US20070245036A1 (en) * 2006-03-03 2007-10-18 Khaled Fekih-Romdhane Illegal commands handling at the command decoder stage
CN102736910A (en) * 2011-05-11 2012-10-17 新奥特(北京)视频技术有限公司 Plugin-based general command interface definition method
CN103049306A (en) * 2011-09-12 2013-04-17 微软公司 Simulation of static members and parameterized constructors on an interface-based api
US20150234667A1 (en) * 2014-02-14 2015-08-20 Red Hat, Inc. Defining classes as singleton classes or non-singleton classes
CN105243018A (en) * 2015-10-24 2016-01-13 北京航空航天大学 Object-oriented class test data generation method
CN106528166A (en) * 2016-11-22 2017-03-22 郑州云海信息技术有限公司 Command line interface processing system and method
US20180357051A1 (en) * 2017-06-13 2018-12-13 Microsoft Technology Licensing, Llc Model binding for command line parsers
CN109683992A (en) * 2017-10-18 2019-04-26 北京京东尚科信息技术有限公司 Method and apparatus for managing object
US20200174804A1 (en) * 2018-12-04 2020-06-04 Sap Se Graphical User Interface Command Pattern
CN111343221A (en) * 2018-12-18 2020-06-26 北京奇虎科技有限公司 Service processing method and device under command mode based on universal interface framework
EP3719643A1 (en) * 2019-04-03 2020-10-07 DreamWorks Animation LLC Extensible command pattern
CN110601880A (en) * 2019-09-02 2019-12-20 平安科技(深圳)有限公司 Cloud platform, service processing method, command interface and computer equipment
CN111221519A (en) * 2019-11-12 2020-06-02 广州银汉科技有限公司 Python-based CLI automatic export method
CN111506307A (en) * 2020-04-10 2020-08-07 北京凌云光技术集团有限责任公司 Parameter chain-based subentry expansion method and system

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
李必信 等: "面向对象的类型-子类型分析及推理规则", 《计算机科学》, vol. 26, no. 7, pages 23 - 27 *
段晓忠;: "以控制台为例来谈设计模式中的命令模式", 统计与管理, no. 07 *

Also Published As

Publication number Publication date
CN112667324B (en) 2023-12-05

Similar Documents

Publication Publication Date Title
US10678536B2 (en) Callable notebook for cluster execution
CN106126215B (en) Business rule scenario generation method and device
US7058955B2 (en) Method and system for passing messages between threads
EP2062136B1 (en) System and method for using stream objects to perform stream processing in a text-based computing environment
JPH0869435A (en) Method and system for transfer of remote procedure call and response through network
US6330711B1 (en) Method and apparatus for dynamic application and maintenance of programs
US9729677B2 (en) Method of adding client server automation to computer languages for cloud computing
CN112835975B (en) Method for deploying, updating and calling intelligent contracts in blockchain
CN109976723B (en) Algorithm development platform, algorithm development method and computer readable storage medium
EP1717715B1 (en) State machine-driven interactive system and associated methods
CN108681491B (en) File decoupling method and system
US6513157B1 (en) System and method for dynamically aggregating objects
US6829575B2 (en) Enterprise javabeans container
CN112667324A (en) Method and device for calling command class in command mode
CN108804088B (en) Protocol processing method and device
US11435989B2 (en) Thread-local return structure for asynchronous state machine
CN115576663A (en) Dynamic deployment method of edge controller, terminal and storage medium
CN115629976A (en) Kernel testing method and device and storage medium
CN112363804B (en) Blockchain JVM application method, device and storage medium
US11429358B2 (en) Representing asynchronous state machine in intermediate code
JPH03184123A (en) Procedure state description element system for digital data processor
US8887125B1 (en) Systems and methods for dynamic artefact substitution
CN106775864B (en) Implementation method of service manager supporting on-demand loading based on Autofac
US20040181784A1 (en) Method of converting software program for single processor to software program for multiprocessor
Rasche et al. Dynamic updates of graphical components in the. Net framework

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant