CN117234500A - Model multi-inheritance method and device implemented by using java language and computer readable storage medium - Google Patents

Model multi-inheritance method and device implemented by using java language and computer readable storage medium Download PDF

Info

Publication number
CN117234500A
CN117234500A CN202311363045.0A CN202311363045A CN117234500A CN 117234500 A CN117234500 A CN 117234500A CN 202311363045 A CN202311363045 A CN 202311363045A CN 117234500 A CN117234500 A CN 117234500A
Authority
CN
China
Prior art keywords
model
inheritance
java
meta
implemented
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.)
Pending
Application number
CN202311363045.0A
Other languages
Chinese (zh)
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.)
Zhejiang Changqingshu Information Technology Co ltd
Original Assignee
Zhejiang Changqingshu Information 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 Zhejiang Changqingshu Information Technology Co ltd filed Critical Zhejiang Changqingshu Information Technology Co ltd
Priority to CN202311363045.0A priority Critical patent/CN117234500A/en
Publication of CN117234500A publication Critical patent/CN117234500A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention belongs to the technical field of computers, and provides a model multi-inheritance method, a device and a computer-readable storage medium realized by using java language, wherein the method comprises the following steps: step S1: annotating the declaration model in the Java class using the model; step S2: when Java runs, reflecting Java classes annotated by the mark model, and acquiring original metadata of the model declaration in the step S1, wherein the original metadata comprises names, inheritance relations, fields and methods of the model; step S3: constructing a meta model according to the inheritance relation of the original meta data; step S4: registering the meta-model to a model registry; step S5: obtaining a meta-model from a model registry according to the model name of the original meta-data; step S6: invoking the meta-model creation method in step S5, instantiating a model dataset. Compared with the technical scheme that a Java class is adopted to realize a plurality of interfaces in the prior art, the method has lower workload in development or program maintenance, and can effectively improve efficiency.

Description

Model multi-inheritance method and device implemented by using java language and computer readable storage medium
Technical Field
The invention belongs to the technical field of computers, and particularly relates to a model multi-inheritance method and device realized by using java language and a computer readable storage medium.
Background
Multiple inheritance has several advantages over single inheritance: multiple inheritance can relay properties and methods from multiple parent classes: (1) Through multiple inheritance, one derived class can obtain the attributes and methods of a plurality of different parent classes at the same time, so that codes have reusability and flexibility, and similar functions are prevented from being realized through code copying and pasting; (2) multiple inheritance can express richer class relationships: some real world problems require modeling using characteristics of multiple different parents, such as: one class has both "animal" and "aircraft" properties. By means of multiple inheritance, the derived classes can directly inherit the different characteristics, and the relations among the classes can be accurately expressed.
The Java language does not support multiple inheritance itself, i.e., one class cannot directly inherit multiple classes. This is one of the design decisions of the Java language, aimed at maintaining the clarity of code, the simplicity of inheritance relationships, and reducing potential conflicts. In the prior art, java can achieve an effect similar to multiple inheritance by using interfaces (interfaces), and Java allows one class to achieve multiple interfaces, so as to obtain functions of the multiple interfaces, which mainly has the following disadvantages: (1) One-time code is required to be copied in each class for realizing the interface so as to finish the realization of the interface, and the workload of development or the workload of program maintenance is large; (2) Only new subclasses can be obtained, the original class is not modified, and the expansion complexity and the code quantity are increased.
Disclosure of Invention
The invention aims to provide a model multi-inheritance method realized by using java language, which aims to solve the technical problems existing in the prior art that similar multi-inheritance is realized by using interfaces.
In order to achieve the above purpose, the technical scheme adopted by the invention is as follows:
a model multi-inheritance method implemented using java language, comprising the steps of:
step S1: annotating the declaration model in the Java class using the model;
step S2: when Java runs, reflecting Java classes annotated by the mark model, and acquiring original metadata of the model declaration in the step S1, wherein the original metadata comprises names, inheritance relations, fields and methods of the model;
step S3: constructing a meta model according to the inheritance relation of the original metadata;
step S4: registering the meta-model to a model registry;
step S5: obtaining a meta-model from a model registry according to the model name of the original meta-data;
step S6: invoking the meta-model creation method in the step S5, instantiating a model dataset providing get/set method read/write fields by the model dataset, values of the fields being stored in a dataset repository, the model dataset providing a method of executing a model by a call method of the model dataset, the model dataset providing a method of executing a parent model of model inheritance by a call super method of the model dataset.
In one embodiment, the step S1 specifically includes using a model annotation declaration model in a Java class:
(1) The name and inheritance relationship of the annotation declaration model are used on Java classes;
(2) In the class of Java, the original metadata of the model field is declared using the static field;
(3) A method of annotating a declaration model is used on a Java method.
In one embodiment, the specific method for constructing the meta-model according to the original meta-data in the step S3 is as follows: and analyzing the final model metadata according to the inheritance relation of the original metadata, and storing the final model metadata as a meta model.
In one embodiment, in the step S3, an inheritance relationship is constructed by dynamically parsing the annotation during running of Java; in the inheritance relationship, fields of the child model cover fields of the parent model, methods of the child model cover methods of the parent model, and when inheritance of a plurality of parent models is performed, inheritance links are analyzed according to the stated order.
In one embodiment, the parsing out the final model metadata includes parsing the name, inheritance relationship, field, method of the model.
In one embodiment, when the model method is analyzed, a model method linked list is constructed according to an MRO algorithm, and the constructed method linked list is stored in a method dictionary.
In one embodiment, when a model method is called, a method linked list is loaded from the method dictionary according to a method name, and the method linked list is matched with a real Java method to call.
In one embodiment, when the methods of the same Java class are used inter-modulation, the methods of all models are intercepted by a dynamic proxy of the Java class, whether the current method should be executed or the calculation according to the model MRO is needed is judged in an interceptor, and the call is made according to the judgment result.
To achieve the above object, the present invention also provides a computer-readable storage medium having stored thereon a computer program that is executed by a processor to implement the model multi-inheritance method implemented using java language.
In order to achieve the above object, the present invention further provides a model multi-inheritance device implemented by using java language, including a processor and a memory; the memory is used for storing a computer program; the processor is connected with the memory and is used for executing the computer program stored in the memory, so that the model multi-inheritance device realized by using the java language executes the model multi-inheritance method realized by using the java language.
Compared with the prior art, the invention has the following beneficial effects:
(1) The business model described in the metadata mode supports multi-inheritance multiplexing, can extract general business logic into an independent model, and can be reused after inheritance in a specific business model; compared with the prior art that Java adopted in one class realizes a plurality of interfaces, one code is required to be copied in each class realizing the interfaces to finish the realization of the interfaces, the invention has lower workload in development or program maintenance and can effectively improve the efficiency.
(2) The model is analytic, and the inheritance relation of the model not only supports multi-inheritance, but also can inherit itself, so that the original model is expanded; after the development of the standard function of the system is completed, the secondary development can be carried out without modifying the original code, and the system can be expanded and upgraded by expanding and inheriting the existing model.
(3) The invention can dynamically analyze annotation to construct inheritance relationship in running, modify inheritance relationship in program running, re-analyze, and has faster and more flexible combination capability than dynamic compiling performance, is suitable for on-line installation and uninstallation of application, and can take effect after new application is installed.
Drawings
FIG. 1 is a schematic flow chart of the present invention-example 1.
Fig. 2 is a schematic block diagram of the present invention-embodiment 3.
Detailed Description
The present invention will be further described in detail with reference to examples so as to enable those skilled in the art to more clearly understand and understand the present invention. It should be understood that the following specific embodiments are only for explaining the present invention, and it is convenient to understand that the technical solutions provided by the present invention are not limited to the technical solutions provided by the following embodiments, and the technical solutions provided by the embodiments should not limit the protection scope of the present invention.
It should be noted that the illustrations provided in the following embodiments merely illustrate the basic concept of the present invention by way of illustration, so that only the components related to the present invention are shown in the drawings and are not drawn according to the number, shape and size of the components in actual implementation, the form, number and proportion of the components in actual implementation may be arbitrarily changed, and the layout of the components may be more complicated.
Example 1
As shown in fig. 1, the present embodiment provides a model multi-inheritance method implemented by using java language, and the design principle of the method is as follows: and the business model is described in a metadata mode by using a parsing operation mode, and the inheritance relation of the model supports multi-inheritance multiplexing.
In this embodiment, the specific steps of the model multi-inheritance method implemented by using java language are as follows:
1. using model annotation declaration model in Java classes
The model is similar to Java class and contains metadata such as name, inheritance relationship, field, method and the like, and the specific contents are as follows:
(1) The name and inheritance relationship of the annotation declaration model are used on Java classes; the declaration model is used on the java class @ model. Meta (name = "model name", inhereit = { "parent model 1", "parent model 2" }), notes model. Meta mainly contains the following: name, title label, inheritance relation information, description, database table, ordering order, method and other information;
(2) In the class of Java, the original metadata of the model field is declared using the static field; the original metadata comprises names, inheritance relations, fields and methods of the models; wherein the fields of the model use Field class declarations, such as static Field name = Field. Char (). Label ("name"); inherited fields are considered as being overwritten if they are of the same name, and the metadata of the fields are converged, the metadata of the fields mainly comprising: name, title label, required to be filled, index, type, etc., and field type contains Char, boolean, string, float, selection, many One, one2Many, many2Many, etc.; the method of the model refers to a java class method meeting the following two conditions: 1. the modifier is public;2. the first parameter is a method of a data set Records, the inherited method is regarded as rewriting with the same name, and the rewritten method is constructed into a model method linked list according to an MRO algorithm;
(3) A method of annotating a declaration model is used on a Java method.
2. At runtime of Java, raw metadata of model declarations is obtained
When Java runs, reflecting Java classes annotated by the mark model to obtain original metadata of the model declaration, wherein the original metadata comprises names, inheritance relations, fields and methods of the model; the contents of the model declaration can be obtained by class.
3. Building a meta-model from inheritance relationships of original metadata
Constructing a meta model according to the original metadata, specifically, analyzing the final model metadata according to the inheritance relation of the original metadata, and storing the final model metadata as a meta model; in the inheritance relationship, fields of the child model cover fields of the parent model, methods of the child model cover methods of the parent model, and when inheritance of a plurality of parent models is carried out, inheritance links are analyzed according to the stated order. The model metadata mainly includes: name, title label, inheritance relation information, description, database table, ordering order, method, field and other information, and all stated model information is stored in a MetaModel meta-model.
By the setting, the inheritance relationship can be constructed by dynamically analyzing the annotation during Java running, so that the inheritance relationship can be modified during program running, and the inheritance relationship can be re-analyzed after modification.
The analysis of the final model metadata includes the name, inheritance relationship, field and method of the analysis model.
When the model method is analyzed, a model method linked list is constructed according to an MRO algorithm (MRO (Method Resolve Order) algorithm of Python language), and the constructed method linked list is stored in a method dictionary.
4. Registering a meta-model to a model registry
All parsed meta-models are registered in the model registry.
5. Obtaining a meta-model from a model registry based on model names of original meta-data
6. Calling meta-model creation method, instantiating a model dataset
Based on the acquired meta-model, invoking a meta-model creation method, and instantiating a model data set; specifically, metadata MetaModel is obtained through a model registry register. Get ("model name"), and a dataset Records is created through MetaModel. Browser (string [ ] ids); and reading and writing fields through the get/set method of the model data set, storing the values of the fields in a data set warehouse, executing the model method through the call method of the model data set, and executing the parent model method inherited by the model through the call super method of the model data set.
After the model is built, the logic for calling the model method is as follows: when the model method is called, a method linked list is loaded from a method dictionary according to the method name, and the method linked list is matched with a real Java method for calling; when the methods of the same Java class are used inter-modulation, the methods of all models are intercepted through a dynamic proxy of the Java class, whether the current method is executed or the calculation is needed according to the MRO of the model is judged in an interceptor, and a correct method is found to be called for calling according to a judging result. For example: a class A, class B and class C are used for declaring a model M, a run method is arranged in the three classes, the inheritance sequence of M is C- > B- > A, a method chain table obtained after construction according to MRO is { run: [ C.run, B.run, A.run ] }, a method run of the model M is called, C.run execution is found from the method chain table, and if a parent model method which is rewritten is called by using a callSuper in the C.run, B.run execution is found from the method chain table.
By adopting the method provided by the embodiment, the inheritance relationship is constructed by dynamically analyzing the annotation in the running process, the inheritance relationship can be modified in the running process of the program, and the analysis can be effective after the modification. For example: model x declares inheritance model m in application app1 and inheritance model n in application app 2; when only application app1 is installed, model x inherits all the characteristics of model m, and when both applications app1, app2 are installed, model x will inherit all the characteristics of m and n at the same time.
Example 2
The present embodiment provides a computer-readable storage medium having stored thereon a computer program that is executed by a processor to implement a model multi-inheritance method implemented using java language provided in embodiment 1. Those of ordinary skill in the art will appreciate that: all or part of the steps of implementing the method provided in embodiment 1 may be implemented by hardware associated with a computer program, where the computer program may be stored in a computer readable storage medium, and when executed, the program performs steps including the method provided in embodiment 1; and the storage medium includes: various media that can store program code, such as ROM, RAM, magnetic or optical disks.
Example 3
As shown in fig. 2, the present embodiment provides a model multi-inheritance device implemented using java language, including: a processor and a memory; the memory is used for storing a computer program; the processor is connected to the memory, and is configured to execute the computer program stored in the memory, so that a model multi-inheritance device implemented using java language performs a model multi-inheritance method implemented using java language provided in embodiment 1.
Specifically, the memory includes: various media capable of storing program codes, such as ROM, RAM, magnetic disk, U-disk, memory card, or optical disk.
Preferably, the processor may be a general-purpose processor, including a central processor, a network processor, etc.; but also digital signal processors, application specific integrated circuits, field programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
The above embodiments are merely illustrative of the principles of the present invention and its effectiveness, and are not intended to limit the invention. Modifications and variations may be made to the above-described embodiments by those skilled in the art without departing from the spirit and scope of the invention. Accordingly, it is intended that all equivalent modifications and variations of the invention be covered by the claims, which are within the ordinary skill of the art, be within the spirit and scope of the present disclosure.

Claims (10)

1. A model multi-inheritance method implemented by using java language, comprising the following steps:
step S1: annotating the declaration model in the Java class using the model;
step S2: when Java runs, reflecting Java classes annotated by the mark model, and acquiring original metadata of the model declaration in the step S1, wherein the original metadata comprises names, inheritance relations, fields and methods of the model;
step S3: constructing a meta model according to the inheritance relation of the original metadata;
step S4: registering the meta-model to a model registry;
step S5: obtaining a meta-model from a model registry according to the model name of the original meta-data;
step S6: invoking the meta-model creation method in the step S5, instantiating a model dataset providing get/set method read/write fields by the model dataset, values of the fields being stored in a dataset repository, the model dataset providing a method of executing a model by a call method of the model dataset, the model dataset providing a method of executing a parent model of model inheritance by a call super method of the model dataset.
2. The method for model multiple inheritance implemented in Java according to claim 1, wherein said step S1 specifically comprises the steps of:
(1) The name and inheritance relationship of the annotation declaration model are used on Java classes;
(2) In the class of Java, the original metadata of the model field is declared using the static field;
(3) A method of annotating a declaration model is used on a Java method.
3. The method for model multi-inheritance implemented in java according to claim 2, wherein the specific method for constructing the meta-model according to the original meta-data in step S3 is as follows: and analyzing the final model metadata according to the inheritance relation of the original metadata, and storing the final model metadata as a meta model.
4. The method for model multiple inheritance implemented in Java language according to claim 3, wherein in step S3, an inheritance relationship is constructed by dynamically parsing the annotation during running of Java; in the inheritance relationship, fields of the child model cover fields of the parent model, methods of the child model cover methods of the parent model, and when inheritance of a plurality of parent models is performed, inheritance links are analyzed according to the stated order.
5. The method of claim 4, wherein parsing out the final model metadata includes parsing the name, inheritance relationship, field, method of the model.
6. The model multi-inheritance method implemented by using java language according to claim 5, wherein when the model method is analyzed, a model method linked list is constructed according to an MRO algorithm, and the constructed method linked list is stored in a method dictionary.
7. The model multi-inheritance method implemented by using Java language according to claim 6, wherein when the model method is called, a method linked list is loaded from the method dictionary according to the method name, and the method linked list is matched with a real Java method for calling.
8. The model multi-inheritance method implemented by using Java language according to claim 7, wherein when the methods of the same Java class are inter-used, the methods of all models are intercepted by the dynamic proxy of the Java class, and it is determined in the interceptor whether the current method should be executed or the calculation according to the model MRO is required, and the call is made according to the determination result.
9. A computer readable storage medium having stored thereon a computer program, wherein the computer program is executed by a processor to implement a model multi-inheritance method implemented in java language according to any of claims 1 to 8.
10. A model multi-inheritance device implemented in java language, comprising: a processor and a memory; the memory is used for storing a computer program; the processor is connected to the memory, and is configured to execute the computer program stored in the memory, so that the model multi-inheritance device implemented using java language performs a model multi-inheritance method implemented using java language according to any one of claims 1-8.
CN202311363045.0A 2023-10-20 2023-10-20 Model multi-inheritance method and device implemented by using java language and computer readable storage medium Pending CN117234500A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311363045.0A CN117234500A (en) 2023-10-20 2023-10-20 Model multi-inheritance method and device implemented by using java language and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311363045.0A CN117234500A (en) 2023-10-20 2023-10-20 Model multi-inheritance method and device implemented by using java language and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN117234500A true CN117234500A (en) 2023-12-15

Family

ID=89091221

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311363045.0A Pending CN117234500A (en) 2023-10-20 2023-10-20 Model multi-inheritance method and device implemented by using java language and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN117234500A (en)

Similar Documents

Publication Publication Date Title
Reussner et al. Modeling and simulating software architectures: The Palladio approach
US10162610B2 (en) Method and apparatus for migration of application source code
US7293254B2 (en) Extensibility application programming interface and framework for meta-model objects
JP5710852B2 (en) A framework for seamless authoring and editing of workflows at design and runtime
US20050091346A1 (en) Settings management infrastructure
US20040015822A1 (en) Method and apparatus for dynamic assembly and verification of software components into flexible applications
KR100942322B1 (en) System and method for defining and using subclasses declaratively within markup
US8943078B2 (en) Methods and systems for simplifying object mapping
Syme et al. Expert F♯ 2.0
US7219341B2 (en) Code analysis for selective runtime data processing
Seibel et al. Traceability in model-driven engineering: efficient and scalable traceability maintenance
WO2020009943A1 (en) System optimized for performing source code analysis
WO2002046909A1 (en) Automatically deploy and upgrade an application based on markup language application definition
US11080102B2 (en) System and method for developing modularized application
US20080172400A1 (en) Techniques to manage an entity model
CN117234500A (en) Model multi-inheritance method and device implemented by using java language and computer readable storage medium
Guerriero et al. StreamGen: Model-driven development of distributed streaming applications
Porres A toolkit for model manipulation
Jensen et al. Pygrametl: A powerful programming framework for easy creation and testing of ETL flows
Sacerdoti Coen A plugin to export Coq libraries to XML
CN117234466B (en) Enterprise management software development method, system, equipment and storage medium
Correia et al. Software Reengineering at the Architectural Level: Transformation of Legacy Systems
US20230244478A9 (en) System Optimized for Performing Source Code
US20230418574A1 (en) Using a semantic tree of a compiler to execute a semantic code query against source code
Sharan Java Language Features: With Modules, Streams, Threads, I/O, and Lambda Expressions

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