基于设计模式的重构方法及工具
详细信息    本馆镜像全文|  推荐本文 |  |   获取CNKI官网全文
摘要
在整个软件生命周期内,大多数的软件系统都需要不断的修改以适应需求的变化,或者为了在不同的应用环境得到重用,必须恰当的改写其中的部分模块。通常这种操作需要非常大的成本消耗,在某种意义上说,通过大量强壮性检测和测试才得到合格程序,不得不针对软件系统的改变进行重新测试,这种活动会一直持续直到此软件生命周期结束。为了应付这种软件维护的相关问题,我们需要一个系统而安全的方法来修改这种运行时或遗留软件系统。
    重构是一种安全的重建技术,它可以使被重建程序保持重建前程序的行为不变。各种各样的重构技术已经被提出,有的可以对用UML类图表示的软件结构进行修改,有的是一些基于源代码的量化度量,或静态分析的自动化程序转换。其共同点是一种重构技术提供了一套基本重构操作,并允许这些基本重构以顺序或组合的方式形成更高级别的重构,这会涉及向个软件质量问题,例如,更高的模块化,表示程度的提高,更低的代码冗余等等。
    设计模式是类、对象、方法间的关系的重现模式的一个集合。每个设计模式描述了它自已的应用领域和基本原则。这样,这种基本原则和应用领域就可以作为高水平重构的一个方向。设计模式模式之所以被广泛使用,是因为它提供了设计级的重用性,可理解性和灵活性。尤其是这种灵活性在某种意义上说使软件的形式更广泛并且对需求变化的敏感度降低。
    本文要讨论的重建是要对一个已存在的面象对象程序自动化引入设计模式。通常的场景是这样的:一个已存在的程序随着新需求的出现将要被扩展,在研究了代码和新需求后,设计者得出结论,已存在的程序结构使想要的扩展很难完成,应该应用某种特定的设计模式来给程序带来必要的灵活性。正在这种情况下,我们决定要尝试提供自动化的程序支持。由设计者选择可应用设计模式和参与重建的程序组件,使用工具对选定的程序组件应用设计模式,同时保持程序的行为不变。本文的目标是使设计者摆脱烦杂而易出错的代码重组过程。在这篇论文里,将展示并论证了这样一种自动化设计模式转换的方法。
    本文的工作是建立在Opdyke的不变式和Robert的组合重构计算的基础上的,描述了组合重构的方式,并展示了一种计算组合重构的前置后置条件的技术。这种技术的重要性在于它作为一个组合重构去实现设计模式的重构,这是通过检查组合的合法性并计算它的整体的前置条件实现的。
    
    
    设计模式转换有很大程度的共性,文中列出了五种模式重构,这些重构已经被实现而且在设计模式的转化开发中有很广泛的应用性。
    本文设计并实现了一个原型设计模式转换工具,实现了在文中讨论的设计模式重构。本文实现的模版方法和策略两种模式重构为已有系统的设计和实现提供了继承和委托两种不同的复用方式。同时还实现了三种创建型模式的重构,其中工厂方法模式重构提供一种推迟对象的创建到子类的机制,从而实现了对产品使用逻辑的复用;建造模式重构使已有系统的产品生成过程与产品的内部表象实现了解藕,使得产品的内象表象可以独立的演化并且把产品内部组成的细节对用户隐藏,而当要产品的生成过程也需要演化时,可以进一步重构过渡到桥模式;单例模式重构为系统提供了一种产生唯一实例的机制,当系统需要全局访问点时可以应用这种重构。
     在本文的讨论方向还有进一步的工作有待未来进行,首先在模式维护方面,应用模式转换改变了程序的代码,而一些变化是需要维护的以保持模式的不变,这意味着某种限制应该加到未来可能的程序演化。例如:具体模板中加入新方法,则要求询问是否要将此方法抽象到抽象模板中,加入这样的限制检查是对本文工作的一个扩展。本文主要是针对Java程序的设计模式的转换,这使本文的方法扩展到应用到其它语言会有一些问题,此外我们希望如果前置条件转化失败,程序可以自动改变以适应等转换的模式,这是未来的一个研究方向,如果能够实现则有望把此方法应用到更广泛的程序转换范围。
Through the software life cycle, most of the developed software sy-stems need to be modified for accommodating requirements changes, or their program modules must be appropriately adapted so as to be reusedin other application contexts. Very often, this kind of maintenance activities requires a very high cost effort, in the sense that the program modules expensively certified through robust verification and testing activities must be certified again against the changes to the software system, and such activities continue to occur until its retirement. To cope with such problems related to software maintenance, we need a systematic and safe approach to modifying the software system, which may be either of a running one or legacy one.
    Refactoring is a safe program restructuring technique that can guarantee the restructured program to preserve the behavior of the original program. Various refactoring techniques have been proposed to modify the software structure which can be represented in the class diagram of UML, and also to transform the program in an automated way based on some quantitative metric or static analysis on the source code. In common, a refactoring technique provides a set of primitive refactoring operations, and allows such primitive operations to be sequentially and combinatorially composed into a high-level refactoring rule, which may involve
    several software quality issues such as higher modularity,performance improvement, lower code redundancy, and so on.
    Design patterns are a collection of recurring patterns of relationships among classes, objects, methods, etc. Each design pattern describes its own application area, structure/ behavior pattern, and rationale. Thus, the rationale and application area can be used as a good goal for high-level refactoring. The design patterns are widely used because they provide design-level reusability, understandability, and flexibility. Especially, the flexibility affords to be focused on in the sense that the program can be formed more openended and less sensitive to the requirements change.
    The restructurings we develop in this thesis will be those that automate the introduction of design patterns to an existing object-oriented program.The scenario we consider is as follows: An existing program is b
    
    
    eing extended with a new requirement. After studying the code and the new requirement,the designer concludes that the existing program structure makes the desired extension di.cult to achieve, and that the application of some particular design pattern would introduce the necessary .exibility to the program. It is at this point that we aim to provide automated tool support. The designer selects the design pattern to be applied and the program components that are to take part in the restructuring, and our tool applies that design pattern to the given program components in such a way that program behaviour is maintained.our aim is to remove the burden of tedious and error-prone code reorganisation from the designer.In this thesis we will present and validate a methodology for the development of automated design pattern transformations.
    Our work is base the programe invariant of Opdyke and compositerefactoring of Robert in which we compose refactorings,and present a technique for computing the pre- and postconditions of a composite refactoring. The importance of these techniques lies in the fact that they allow us to implement a design pattern refactoring as a composition of refactorings and then to check the legality of the composition and calculate its overall precondition. Design pattern transformations have astrong degree of commonality and this paper describes five design pattern refactorings.These refactoring have been implemented and demonstrated to be widely applicable in design evolvement development.
    This thesis design and implementation a design pattern refactoring prototype tools,and implementation five design pattern refactoring that hava been discussed in this thesis.Template method pattern refactoring and strategy pattern provide two kind reus
引文
[1] M. Fowler.and Addison-Wesley. Refactoring : Improving the design of existing programs.1999.
    [2] Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides. DesignPatterns : Elements of Reusable Object-Oriented
    [3] 阎宏。Java与模式 :电子工业出版社。2002.10
    [4] Sang-Uk Jeon, Joon-Sang Lee, and Doo-Hwan Bae. An Automated
    Refactoring Approach to Design Pattern-based Program Transformations in Java Programs.the Ninth-Pacific Software Enigneering Conference(APSEC’02)
    [5] Kent Beck. Extreme Programming Explained. Addison Wesley Longman,Reading, Massachusetts, .rst edition, 2000.
    [6] Joshua Kerievsky. Refactoring To Patterns. Industrial Logic, Inc.
    [7] Donald Roberts. Eliminating Analysis in Refactoring. PhD dissertation,University of Illinois at Urbana-Champaign, Department of ComputerScience, 1999.
    [8] William F. Opdyke. Refactoring Object-Oriented Frameworks. PhD
    dissertation, University of Illinois at Urbana-Champaign, Department
    of Computer Science, 1992.
    [9] L. Tokuda and D. Batory. Automating Three Modes of Object-Oriented Software Evolution. In Proceedings, COOTS ’99, 1999.
    [10] John Brant, Brian Foote, Ralph Johnson, and Don Roberts. Wrappers to the rescue. In Eric Jul, editor, Proceedings of the European Conference on Object-Oriented Programming, Brussels, July 1998. LNCS.
    [11] Michael L. Brodie and Michael Stonebraker. Migrating Legacy Systems:Gateways, Interfaces and the Incremental Approach. Morgan Kaufman,San Francisco, 1995.
    [12] Ivan R. Moore and Tim P. Clement. A simple and e.cient algorithm for inferring inheritance hierarchies. In TOOLS Europe, pages 173–184,Paris, February 1996. Prentice-Hall.
    [13] Serge Demeyer, St′ephane Ducasse, and Oscar Nierstrasz. A pattern language for reverse engineering. In Fifth European Conferenc
    
    
    eon Pattern Languages of Programs (EuroPLoP), Irsee, Germany, July 2000.
    [14] Serge Demeyer, T.D. Meijler, and Matthias Riegler. Towards design
    pattern transformations. In ECOOP Workshop Object-Oriented Software Evolution and Re-Engineering, Finland, June 1997. Springer-Verlag LNCS1241.
    [15] Frank Buschmann, Regine Meunier, Hans Rohnert, Peter Sommerlad,and Michael Stal. A System of Patterns: Pattern-Oriented Software
    Architecture. John Wiley & Sons, Chicester, .rst edition, 1996.
    [16] Eduardo Casais. Managing Evolution in Object Oriented Environments: an Algorithmic Approach. PhD dissertation, University of Gen
    [17]《Java 2核心技术 卷II:高级性能》Cay S. Horstmann, Gary Cornell著,王建华、董志敏、扬保明 等译,机械工业出版社2003年1月第1版
    [18] Keith Bennett and Vaclaw Rajlich. Software maintenance and evolution: A roadmap. In Anthony Finkelstein, editor, The Future of Software Engineering, New York, 2000. ACM Press. Produced as part of ICSE 2000, Limerick, Ireland.
    [19]《敏捷软件开发 原则、模式与实践》Robert C.Martin 著,邓辉 译,
     清华大学出版社2003年9月第1版
    [20] Lucy M. Berlin. When objects collide: experiences with reusing multiple class hierarchies. In Object-Oriented Programming Systems, Languages and Applications Conference, pages 181–193, Ottawa, Canada,October 1990. ACM Press.
    [21]《Java 2核心技术 卷I:原理》Cay S. Horstmann, Gary Cornell著,李如豹、刚冬梅 等译,机械工业出版社2002年2月第1版
    [22] Grady Booch. Object-oriented analysis and design with applications.
    Benjamin/Cummings, Redwood City, California, second edition, 1994.

© 2004-2018 中国地质图书馆版权所有 京ICP备05064691号 京公网安备11010802017129号

地址:北京市海淀区学院路29号 邮编:100083

电话:办公室:(+86 10)66554848;文献借阅、咨询服务、科技查新:66554700