MDA代码生成技术

上传人:新** 文档编号:506622129 上传时间:2023-07-05 格式:DOCX 页数:8 大小:72.72KB
返回 下载 相关 举报
MDA代码生成技术_第1页
第1页 / 共8页
MDA代码生成技术_第2页
第2页 / 共8页
MDA代码生成技术_第3页
第3页 / 共8页
MDA代码生成技术_第4页
第4页 / 共8页
MDA代码生成技术_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《MDA代码生成技术》由会员分享,可在线阅读,更多相关《MDA代码生成技术(8页珍藏版)》请在金锄头文库上搜索。

1、关于代码生成技术Working in Java either means writing a little bit of complex code or writing a lot of gruntwork code. J2EE is a prime example; implementing the persistence for a single database table takes five classes and two interfaces using EJBs, and almost all of the classes are clerical work. We have t

2、o write them, but we dont have to do it by hand. Code-generation techniques can make building high-quality EJB code a breeze.Will code generation revolutionize computing and change the way we develop forever? Yes, but it will take a while. Software engineering has always concentrated on increasing o

3、ur level of abstraction. In the beginning, we hand-wrote machine code; then we created assemblers and macro assemblers. After that, we created Fortran and compiled our code into assembler. Then came structure programming, and after that, object-oriented programming. With each step, we have increased

4、 our level of abstraction and, thus, our ability to create higher quality applications with more functionality, more quickly.What is Code Generation?What is this panacea for developers called code generation? Code generation is the technique of writing and using programs that build application and s

5、ystem code. To understand code generation, you need to understand what goes in and what comes out. What goes in is the design for the code in a declarative form: I need two tables named book and author with these fields. What comes out is one or more target files. It could be Java code, deployment d

6、escriptors, SQL, documentation, or any type of controlled output.Figure 1 shows the basic form of todays code generators:Figure 1. The process of code generationThe components can change slightly between the different models, but the song remains the same.The code generator readsin the design, then

7、uses a set of templates to build output code that implements the design. The separation between code generation logic in the generator and output formatting in the templates is akin to the separation between business logic and user interfaces in web applications.Code generators are not wizards. Wiza

8、rds are passive generators. They write code once, and then its up to you to maintain the code forever. Code generators are active. They continually maintain code over multiple generation cycles. As the designs change, the input to the generator changes, and new code is created to match the design. T

9、his is a key advantage when have you been on a project where the requirements dont change?What Are the Benefits?Before we get into specific examples of code generators for Java, lets make sure we have the end goals firmly in mind. One way to approach this is to think about the qualities we want in a

10、n optimal generator. Quality: We want the output code to be at least as good as what we would have written by hand. Thankfully, the template-based approach of todays generators builds code that is easy to read and debug. Because of the active nature of the generator, bugs found in the output code ca

11、n be fixed in the template. Code can then be re-generated to fix that bug across the board. Consistency: The code should use consistent class, method, and argument names. This is also an area where generators excel because, after all, this is a program writing your code. Productivity: It should fast

12、er to generate the code than to write itbyhand.Thisisthefirstbenefitthatmostpeoplethinkofwhen it comes to generation. Strangely, you may not achieve this on the first generation cycle. Thankfully, the real productivity value comes later, as you re-generate the code base to match changing requirement

13、s; at this point you will blow the hand-coding process out of the water in terms of productivity. Abstraction:Weshouldbeabletospecifythedesigninanabstract form,freeofimplementationdetails.Thatwaywecanre-targetthe generator atalater date if wewant to moveto another technology platform.Now that we und

14、erstand that benefits that we want, and how those are addressed by code generation techniques in general, we should understand what we expect to use code generation for in the Java context.What We Expect the Generator to HandleThe output files of a generator are called the target files. There are se

15、veral generation targets within the Java enterprise application stack. Figure 2 shows the stack:Figure 2. J2EE generation targetsAll four of these elements of the stack are potential generation targets, but some are more common than others. From the bottom to the top: Database: Given Javas object-pe

16、rsistence approaches to database work, there isnt much call for direct generation of SQL for database code or stored procedures. However, if this is your architecture, you can use the custom approaches listed below to generate the required code. Persistence : Database persistence code is the most common generation target in the Java environment. All of the generators Irefertointhesectionsthatfollowbuildpersistencecode.Why? Its

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号