A method, system, electronic device and storage medium for generating instantiated objects

By pre-creating instantiated objects of abstract classes and factory classes on the server and returning directly when requested by the client, the problem of inefficient instantiation object generation is solved, efficient resource management and code maintenance are realized, and program capability is improved Extensibility.

CN111752551BActive Publication Date: 2024-11-05GUANGDONG INSPUR BIG DATA RES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010604995.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-29
Publication Date
2024-11-05
Estimated Expiration
2040-06-29

AI Technical Summary

Technical Problem

In the prior art, the generation efficiency of instantiated objects is low, and frequent calls to new functions are required to lead to waste of resources and maintenance difficulties.

Method used

By creating abstract classes and factory classes, the instantiation objects of concrete classes are generated using inheritance, and the objects are created in advance on the server side, and the client request is returned directly to avoid re-instantiation on the client side.

Benefits of technology

It improves the efficiency of instantiated object generation, reduces memory usage and resource waste, and supports code maintenance and object lifecycle management, improving the scalability and maintenance of the program.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111752551B_ABST
    Figure CN111752551B_ABST
Patent Text Reader

Abstract

The present application discloses a method for generating an instantiated object, which is applied to a server. The method for generating an instantiated object includes creating an abstract class, and generating multiple concrete classes corresponding to the abstract class by inheritance; constructing a factory class, and using the factory class to create an instantiated object of the concrete class; if an instantiated object creation request of a target concrete class sent by a client is received, the instantiated object of the target concrete class is returned to the client. The present application can improve the efficiency of instantiated object generation. The present application also discloses a system for generating instantiated objects, a storage medium, and an electronic device, which have the above beneficial effects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method and system for generating an instantiated object, a storage medium and an electronic device. Background Art

[0002] Instantiating an object refers to the process of making an abstract concept class concrete to the physical object of that class. With the development of programming technology, object-oriented programming has emerged, advocating that everything is an object. The basic object-oriented abstract method is to abstract one or a class of similar things into a class. This class contains the common functions and variables of this thing, and then pass these common characteristics to this type of thing through inheritance. At the same time, this type of thing can also be specifically modified and variables and functions can be added and modified to concretize this specific class, so that this concrete instance can be instantiated. However, in the instantiation process, the general method is to use the new function to create a specific instance of this specific class. Each time an instantiated object is generated, the new function needs to be called, and the generation efficiency of instantiated objects is low.

[0003] Therefore, how to improve the efficiency of instantiated object generation is a technical problem that those skilled in the art currently need to solve. Summary of the invention

[0004] The purpose of this application is to provide a method and system for generating an instantiated object, a storage medium and an electronic device, which can improve the efficiency of instantiated object generation.

[0005] In order to solve the above technical problems, the present application provides a method for generating an instantiated object, which is applied to a server. The method for generating an instantiated object includes:

[0006] Create an abstract class, and generate multiple concrete classes corresponding to the abstract class through inheritance;

[0007] Constructing a factory class, and using the factory class to create an instantiation object of the specific class;

[0008] If a request for creating an instantiated object of a target specific class sent by a client is received, the instantiated object of the target specific class is returned to the client.

[0009] Optionally, also include:

[0010] Setting a life cycle for the specific class in the factory class;

[0011] If the instantiated object exists in the client for a period longer than the life cycle of the specific class corresponding to the instantiated object, the instantiated object is cleared.

[0012] Optionally, also include:

[0013] Create a new concrete class and set the inheritance relationship of the new concrete class; wherein the new concrete class inherits the created abstract class;

[0014] The factory class is used to create an instantiated object of the new specific class.

[0015] Optionally, constructing a factory class and using the factory class to create an instantiation object of the specific class includes:

[0016] Construct a factory class, and construct an instantiation object creation method in the factory class;

[0017] The instantiated object of the specific class is created using the instantiated object creation method.

[0018] Optionally, also include:

[0019] If a first code file maintenance instruction is received, a maintenance operation is performed on the code file in the server according to the code file maintenance instruction; wherein the code file in the server includes the code file of the abstract class and / or the concrete class and / or the factory class.

[0020] Optionally, also include:

[0021] If a second code file maintenance instruction is received, a maintenance operation is performed on the code file in the client according to the code file maintenance instruction; wherein the code file in the client includes the code file of the instantiated object of the target specific class.

[0022] Optionally, the instantiated object creation request includes the target specific class and object name;

[0023] Accordingly, returning the instantiated object of the target specific class to the client includes:

[0024] Parsing the object creation request to obtain object feature information; wherein the object feature information includes an object name and / or an object type;

[0025] The instantiated object is generated according to the object feature information, and the instantiated object is returned to the client. The present application also provides a system for generating instantiated objects, which is applied to a server, and the system includes:

[0026] A concrete class generation module is used to create an abstract class and generate multiple concrete classes corresponding to the abstract class by inheritance;

[0027] An instantiation module, used to construct a factory class and use the factory class to create an instantiation object of the specific class;

[0028] The object returning module is used to return the instantiated object of the target specific class to the client if a request for creating an instantiated object of the target specific class is received from the client.

[0029] The present application also provides a storage medium on which a computer program is stored. When the computer program is executed, the steps of the method for generating an instantiated object are implemented.

[0030] The present application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the processor calls the computer program in the memory, the steps of the instantiated object generation method are implemented.

[0031] The present application provides a method for generating an instantiated object, including creating an abstract class and generating multiple concrete classes corresponding to the abstract class by inheritance; constructing a factory class and using the factory class to create an instantiated object of the concrete class; if a request for creating an instantiated object of a target concrete class sent by a client is received, the instantiated object of the target concrete class is returned to the client.

[0032] The present application first creates an abstract class and generates multiple concrete classes of the abstract class, and creates an instantiated object corresponding to each concrete class in the factory class, that is, there are multiple instantiated objects in the factory class. If a request for creating an instantiated object of a target concrete class sent by a client is received, the instantiated object of the target concrete class is directly returned to the client from the factory class. In the above process, there is no need to call the new function to create an instantiated object after receiving the request for creating an instantiated object, but directly send the instantiated object that has been generated to the client, so the present application can improve the efficiency of instantiated object generation. The present application also provides a system for generating instantiated objects, a storage medium and an electronic device, which have the above-mentioned beneficial effects and are not repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0034] Figure 1 A flowchart of a method for generating an instantiated object provided in an embodiment of the present application;

[0035] Figure 2 A schematic diagram of the principle of a method for instantiating objects in an extensible object-oriented editing provided in an embodiment of the present application;

[0036] Figure 3 A schematic diagram of the structure of a system for generating instantiated objects provided in an embodiment of the present application. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0038] See below Figure 1 , Figure 1 A flowchart of a method for generating an instantiated object provided in an embodiment of the present application.

[0039] Specific steps may include:

[0040] S101: Create an abstract class, and generate multiple concrete classes corresponding to the abstract class by inheritance;

[0041] Among them, this embodiment can be applied to the server, and multiple abstract classes (i.e., abstract class classes) can be created in the server, and multiple concrete classes corresponding to the abstract classes can be generated by inheritance (extend). This embodiment does not limit the number of abstract classes, nor does it limit the number of concrete classes corresponding to each abstract class.

[0042] S102: construct a factory class, and use the factory class to create an instantiation object of the specific class;

[0043] Wherein, the factory class can be a class created by its getInstance method, and the factory class can instantiate an object only once, thereby improving work efficiency. After constructing the factory class, the present embodiment can utilize the factory class to create an instantiated object of a specific class, and the present embodiment can also store the instantiated object in the factory class.

[0044] As a feasible implementation method, the process of using a factory class to create an instantiated object of a specific class in this embodiment includes: constructing an instantiated object creation method in the factory class, and using the instantiated object creation method to create an instantiated object of the specific class.

[0045] Furthermore, this embodiment can also determine whether the server creates a new specific class. If a new specific class is created, the inheritance relationship of the new specific class is set; wherein the new specific class inherits the created abstract class; and the factory class is used to create an instantiation object of the new specific class.

[0046] S103: If a request for creating an instantiated object of a target specific class sent by a client is received, the instantiated object of the target specific class is returned to the client.

[0047] The server used in this embodiment can be connected to any number of clients and can receive a request to create an instantiated object of a target specific class sent by the client. The request to create an instantiated object of a target specific class is a request to request the server to return an instantiated object of the target specific class. After receiving the request to create an instantiated object of a target specific class sent by the client, this embodiment can return the instantiated object of the target specific class pre-created in the factory class to the client.

[0048] As a feasible implementation method, the instantiated object creation request mentioned in this embodiment may include a target specific class and an object name; accordingly, the process of returning the instantiated object of the target specific class to the client may include: parsing the object creation request to obtain object feature information; wherein, the object feature information includes an object name, may include an object type, and may also include an object name and an object type.

[0049] This embodiment first creates an abstract class and generates multiple concrete classes of the abstract class, and creates an instantiated object corresponding to each concrete class in the factory class, that is, there are multiple instantiated objects in the factory class. If a request to create an instantiated object of a target concrete class sent by a client is received, the instantiated object of the target concrete class is directly returned to the client from the factory class. In the above process, there is no need to call the new function to create an instantiated object after receiving the request to create an instantiated object, but directly send the instantiated object that has been generated to the client, so this embodiment can improve the efficiency of instantiated object generation.

[0050] As for Figure 1 Further introduction to the corresponding embodiment, the above embodiment can also set a life cycle for the specific class in the factory class; if the instantiated object exists in the client for a longer time than the life cycle of the specific class corresponding to the instantiated object, the instantiated object is cleared. By regularly clearing the instantiated object, memory overflow can be prevented and program operation efficiency can be improved.

[0051] As for Figure 1 For further introduction to the corresponding embodiment, the present embodiment may include operations for maintaining code files in the server and / or client. Specifically, the following two maintenance methods may be included:

[0052] Method 1: If a first code file maintenance instruction is received, a maintenance operation is performed on the code file in the server according to the code file maintenance instruction; wherein the code file in the server includes the code file of the abstract class and / or the concrete class and / or the factory class.

[0053] Mode 2: If a second code file maintenance instruction is received, a maintenance operation is performed on the code file in the client according to the code file maintenance instruction; wherein the code file in the client includes the code file of the instantiated object of the target specific class.

[0054] The following is an example of an actual application to illustrate the process described in the above embodiment. Figure 2 , Figure 2 A schematic diagram of the principle of a method for instantiating objects in an extensible object-oriented editing provided in an embodiment of the present application. This embodiment optimizes the way of instantiating objects in object-oriented programming by rationally utilizing mechanisms such as inheritance and rewriting in object-oriented programming, thereby achieving high cohesion and low coupling in programming and easy-to-expand, easy-to-use, and easy-to-maintain code effects.

[0055] The process of instantiating objects in traditional object-oriented programming is: abstract a general class of things to form an abstract general class, and then the general class corresponding to this class of things can be represented by this general abstract class, which contains all the common characteristics of this class of things. These characteristics are abstracted as general member variables and functions in this class. After that, the specific classes contained in this class of things reuse these common codes through inheritance and extend, and inherit all the common characteristics of this class of things in terms of abstract logic. At the same time, you can also add and modify all the characteristics of these specific classes that are different from other classes of things, which are also represented by adding and modifying member variables and class methods. After modifying and changing the specific class, instantiate this class in a new way to generate an object, so that this object can play all the functions described in the class. If you want to use the methods in this class, you need to instantiate this object in a new way. This leads to a series of problems: the code is not structured enough, the cohesion of each object is too low, and the coupling is relatively high, which violates the basic programming requirements of high cohesion and low coupling. The code written in this way is still difficult to maintain, has high reusability, and has low efficiency in generating instantiated objects.

[0056] To solve the above problems, Figure 2As shown in the present embodiment, a factory class factory is first abstracted. This factory class has a factory method makeObj. The factory method makeObj is responsible for instantiating the class. This factory class factoryClass is dependent on the corresponding traditional concrete class. Then, these concrete classes can be managed through this factory class. Both the instantiation of these classes and the management of their life cycles can be monitored and managed through this class. The specific process is as follows: First, a class of things is abstracted to generate an abstract class class. This class then maintains the common features of this class of things, represented by member variables and member methods. After that, the concrete classes of this class of things can pass the common parts represented in the abstract class through inheritance. At the same time, these concrete classes can also modify themselves to achieve the purpose by adding and modifying the member variables and member methods of the class. This embodiment abstracts a factory class and makes these specific classes dependent on this factory class. When the client needs to create an instantiated object, it no longer creates the object through new, but creates the object through the factory class factoryClass. This avoids continuous new objects and memory overflow. In order to save memory, functions for life cycle management of the managed objects can be added to the factory class to further control the life cycle of the objects, release memory in time, and improve program running efficiency. At the same time, code maintenance is also easier. Traditional code maintenance can only be maintained at the server, while this embodiment can be maintained at the server and / or client. At the same time, the scalability of the program is greatly improved. For example, to add a new class, you only need to inherit an abstract class and then add a dependency in the factory, which meets the programming characteristics of high cohesion and low coupling.

[0057] This embodiment optimizes the way of instantiating objects in object-oriented programming by rationally utilizing mechanisms such as inheritance and overriding in object-oriented programming, thereby achieving high cohesion and low coupling in programming and code effects that are easy to expand, use, and maintain, thereby improving the efficiency of instantiated object generation.

[0058] See also Figure 3 , Figure 3 A schematic diagram of a system for generating an instantiated object provided in an embodiment of the present application, the system may include:

[0059] A concrete class generation module 100 is used to create an abstract class and generate multiple concrete classes corresponding to the abstract class by inheritance;

[0060] The instantiation module 200 is used to construct a factory class and use the factory class to create an instantiation object of the specific class;

[0061] The object returning module 300 is configured to return the instantiated object of the target specific class to the client upon receiving a request to create an instantiated object of the target specific class sent by the client.

[0062] This embodiment first creates an abstract class and generates multiple concrete classes of the abstract class, and creates an instantiated object corresponding to each concrete class in the factory class, that is, there are multiple instantiated objects in the factory class. If a request to create an instantiated object of a target concrete class sent by a client is received, the instantiated object of the target concrete class is directly returned to the client from the factory class. In the above process, there is no need to call the new function to create an instantiated object after receiving the request to create an instantiated object, but directly send the instantiated object that has been generated to the client, so this embodiment can improve the efficiency of instantiated object generation.

[0063] Furthermore, it also includes:

[0064] A periodic clearing module is used to set a life cycle for the specific class in the factory class; and is also used to clear the instantiated object if the time the instantiated object exists in the client is longer than the life cycle of the specific class corresponding to the instantiated object.

[0065] Furthermore, it also includes:

[0066] The new concrete class processing module is used to create a new concrete class and set the inheritance relationship of the new concrete class; wherein the new concrete class inherits the created abstract class; and is also used to use the factory class to create an instantiation object of the new concrete class.

[0067] Furthermore, the instantiation module 200 is used to construct a factory class and to construct an instantiation object creation method in the factory class; and is also used to create an instantiation object of the specific class using the instantiation object creation method.

[0068] Furthermore, it also includes:

[0069] The first maintenance module is used to perform maintenance operations on the code files in the server according to the code file maintenance instruction if a first code file maintenance instruction is received; wherein the code files in the server include code files of the abstract class and / or the concrete class and / or the factory class.

[0070] Furthermore, it also includes:

[0071] The second maintenance module is used to perform maintenance operations on the code files in the client according to the code file maintenance instruction if a second code file maintenance instruction is received; wherein the code files in the client include code files of instantiated objects of the target specific class.

[0072] Further, the instantiated object creation request includes the target specific class and object name;

[0073] Correspondingly, the object return module 300 is used to parse the object creation request to obtain object feature information; wherein the object feature information includes the object name and / or object type; and is also used to generate the instantiated object according to the object feature information, and return the instantiated object to the client.

[0074] Since the embodiments of the system part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the system part, which will not be repeated here.

[0075] The present application also provides a storage medium on which a computer program is stored, and when the computer program is executed, the steps provided in the above embodiment can be implemented. The storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0076] The present application also provides an electronic device, which may include a memory and a processor, wherein a computer program is stored in the memory, and when the processor calls the computer program in the memory, the steps provided in the above embodiment may be implemented. Of course, the electronic device may also include various network interfaces, power supplies and other components.

[0077] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of this application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of this application.

[0078] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises", "comprising" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

Claims

1. A method for generating an instantiated object, characterized in that: Applied to the server, including: Create an abstract class, and generate multiple concrete classes corresponding to the abstract class through inheritance; Constructing a factory class, and using the factory class to create an instantiation object of the specific class; If a request to create an instantiated object of a target specific class is received from a client, the instantiated object of the target specific class is returned to the client; The method for generating the instantiated object further includes: Setting a life cycle for the specific class in the factory class; If the instantiated object exists in the client for a period longer than the life cycle of the specific class corresponding to the instantiated object, clearing the instantiated object; The method for generating the instantiated object further includes: Create a new concrete class and set the inheritance relationship of the new concrete class; wherein the new concrete class inherits the created abstract class; Using the factory class to create an instantiated object of the new specific class; The step of constructing a factory class and using the factory class to create an instantiation object of the specific class includes: Construct a factory class, and construct an instantiation object creation method in the factory class; Creating an instantiated object of the specific class using the instantiated object creation method; The method for generating the instantiated object further includes: If a first code file maintenance instruction is received, a maintenance operation is performed on the code file in the server according to the code file maintenance instruction; wherein the code file in the server includes the code file of the abstract class and / or the concrete class and / or the factory class; The method for generating the instantiated object further includes: If a second code file maintenance instruction is received, a maintenance operation is performed on the code file in the client according to the code file maintenance instruction; wherein the code file in the client includes a code file of an instantiated object of the target specific class; Wherein, the instantiated object creation request includes the target specific class and object name; Accordingly, returning the instantiated object of the target specific class to the client includes: Parsing the object creation request to obtain object feature information; wherein the object feature information includes an object name and / or an object type; Generate the instantiated object according to the object feature information, and return the instantiated object to the client; The method for generating the instantiated object further includes: Adding a function for life cycle management of the managed object in the factory class to control the life cycle of the managed object; Wherein, the server is connected to any number of the clients; Wherein, a factory class factory is abstracted, the factory class includes a factory method makeObj, the factory method makeObj is used to instantiate a class, and the factory class factory is dependently associated with a traditional specific class, so that the traditional specific class is managed by the factory class factory; The factory class factory includes instantiating a primary object during the process of instantiating an object.

2. A system for generating instantiated objects, characterized in that: Applied to the server, including: A concrete class generation module is used to create an abstract class and generate multiple concrete classes corresponding to the abstract class by inheritance; An instantiation module, used to construct a factory class and use the factory class to create an instantiation object of the specific class; The object returning module is used to return the instantiated object of the target specific class to the client if a request for creating an instantiated object of the target specific class is received from the client; Wherein, the instantiated object generation system is also used for: Setting a life cycle for the specific class in the factory class; If the instantiated object exists in the client for a period longer than the life cycle of the specific class corresponding to the instantiated object, clearing the instantiated object; Create a new concrete class and set the inheritance relationship of the new concrete class; wherein the new concrete class inherits the created abstract class; Using the factory class to create an instantiated object of the new specific class; Wherein, the instantiation module is specifically used for: Construct a factory class, and construct an instantiation object creation method in the factory class; Creating an instantiated object of the specific class using the instantiated object creation method; Wherein, the instantiated object generation system is also used for: If a first code file maintenance instruction is received, a maintenance operation is performed on the code file in the server according to the code file maintenance instruction; wherein the code file in the server includes the code file of the abstract class and / or the concrete class and / or the factory class; If a second code file maintenance instruction is received, a maintenance operation is performed on the code file in the client according to the code file maintenance instruction; wherein the code file in the client includes a code file of an instantiated object of the target specific class; Wherein, the instantiated object creation request includes the target specific class and object name; Accordingly, the object return module is specifically used for: Parsing the object creation request to obtain object feature information; wherein the object feature information includes an object name and / or an object type; Generate the instantiated object according to the object feature information, and return the instantiated object to the client; Wherein, the instantiated object generation system is also used for: Adding a function for life cycle management of the managed object in the factory class to control the life cycle of the managed object; Wherein, the server is connected to any number of the clients; Wherein, a factory class factory is abstracted, the factory class includes a factory method makeObj, the factory method makeObj is used to instantiate a class, and the factory class factory is dependently associated with a traditional specific class, so that the traditional specific class is managed by the factory class factory; The factory class factory includes instantiating a primary object during the process of instantiating an object.

3. An electronic device, characterized in that: The invention comprises a memory and a processor, wherein a computer program is stored in the memory, and when the processor calls the computer program in the memory, the steps of the method for generating an instantiated object as claimed in claim 1 are implemented.

4. A storage medium, characterized in that: The storage medium stores computer executable instructions, and when the computer executable instructions are loaded and executed by the processor, the steps of the method for generating an instantiated object as described in claim 1 above are implemented.