Towards Specalzaton of the Contract-Aware Software Development Process Anna Derezńska, Przemysław Ołtarzewsk Insttute of Computer Scence, Warsaw Unversty of Technology, Nowowejska 5/9, 00-665 Warsaw, Poland A.Dereznska @.pw.edu.pl Abstract. The contract-based software mplementaton mproves accuracy and verfcaton capabltes of busness nformaton systems. Ths paper promotes contract dentfcaton n early phases of the software development and defnng contracts wthn models. Desgn and mplementaton artfacts that are responsble for system functonalty and system constrants are transformed durng the consecutve development phases. Combnaton of the Model Drven Engneerng paradgm and Desgn by Contract deas consttutes the Contract Aware Software Development process (CASD). The approach s specalzed for system modelng n UML, contracts specfed at model level n Object Constrant Language (OCL), and the fnal mplementaton n the C# language. The specalzed process s supported by the tool transformng the models wth assocated contracts nto the correspondng programs wth contracts at the code level. Keywords: software development process, Model Drven Engneerng, UML, contracts, OCL Introducton An apparent dscrepancy between a system specfcaton and ts mplementaton s a common problem arsen n busness systems. A tendency to overlook system constrants can be especally observed durng requrement analyss and software modelng and desgn. The constrants are often modfed, as n the evoluton of enterprse systems. These error-prone phenomena result n ncrease of the number of system faults and hgh costs of a software correcton and mantenance. The answer to these problems lays n usng contracts through the whole software development process, ncludng especally modelng actvtes. Contracts can be understood n general as condtons that must be true for the whole lfe tme of a system unt, or be satsfed at certan tme ponts of a unt behavor. A unt s represented by dfferent knds of models or software descrptons. Desgn-by-contract (DbC TM ) [] s a technque that reles on the specfcaton of contracts and s prmarly used at the code level. However, the code contracts org- http://www.sprngerlnk.com/content/x6587l60k0445806 The orgnal publcaton s avalable at www.sprngerlnk.com
Towards Specalzaton of the Contract-Aware Software Development Process nate from constrants specfed n busness rules and software requrements. Consequently the contracts could already be expressed n models at the system desgn level. Ths paper s focused on the applcaton of the contract-based methodology combned wth model-drven engneerng [2]. We propose a general approach, so-called Contract-Aware Software Development (CASD) process [3], n whch busness system constrans are specfed as contracts and appled to system models. Next, the models wth assocated contracts can be refned and transformed nto the code level. Ths generc approach can be specalzed towards dfferent modelng languages, e.g. UML, and varous contract technologes. A language used for formulatng of constrants n UML models s the Object Constrant Language (OCL) [4,5]. However, n order to acheve the antcpated objectves t s ndspensable to provde an nfrastructure supportng the approach. Contract to code transformaton s ntegral to the way the methodology s appled. The contract mplementaton effort s moved to the dscussed transformaton tool. Therefore, the code s consstent wth the specfcaton. Moreover, the labor requred for the contract mantenance can be lowered. In the next Secton, the man ssues of the Contract-Aware Software Development process are specfed. Secton 3 presents a soluton adaptng the process to selected technologes. In further sectons we dscuss how some deas of the CASD process are appled wth the tool support and related to other work. Secton 6 concludes the paper. 2 Contract-Aware Software Development Contract-Aware Software Development (CASD) s an approach to a generc process that combnes features of the contract-based and model-drven development. The prelmnary draft of the process was presented n [3,6]. The man phases of the process and ts basc artfacts are llustrated n Fg.. Dual artfacts encounter n varous phases of the process, from the analyss to the mplementaton one. The artfacts shown on the left hand sde correspond to a system functonalty, whereas the opposte elements represent constrants and contracts. The artfacts wthn a development phase are related by a constran dependency. It represents the couplng between the system functonalty and the correspondng contract at the same abstracton level. The nter-phase relatons are defned by transform and trace dependences. Transform dependences llustrate the gradual refnement of the artfacts durng the development process. The latter dependences are responsble for defnng traceablty to the orgnal artfacts. Durng the system development and mantenance, changes n a contract made at the -th level of abstracton should also be ncorporated to the prevous level. Ths fact denotes the need for the round trp engneerng, whch refers to the contracts as well as to the functonal artfacts. Both types of the artfacts should be transferred nto the next abstract level n a common step. In general, the basc concepts of the process are defned as a fnte sequence < L, δ, L 2,... δ n, L n + > ncludng two knds of elements. The frst knd of elements L = F, C, λ ) s a tuple denotng an th level of a system abstracton, where: ( = n+ s a number of a consdered level of system abstracton, th level s more abstract than (+) th level,
A. Derezńska and P. Ołtarzewsk F s a fnte set of functonalty artfacts at the th level of system abstracton, C s a fnte set of contracts at the th level of system abstracton, λ : C F s a functon representng the constran dependences. The second knd of elements n the process s a transformaton functon between two F C F + adjacent levels of system abstracton: : 2 2 2 + C δ 2, where 2 X denotes a power set of set X and = n. The transformaton functon satsfes the followng mplcaton: (( λ ( c ) ( f c {(( λ ( c ) = f ) δ (( δ ( A, B ) = ( A, B )) ( f A ) ( c B ))) () λ + + + ) = f + + A + + ) ( c + + B where: f F f F are functonalty artfacts from the th and + th levels, c, + +, C c+ C+ F F C 2, A + 2, B 2, B + A + ))} are contracts from the th and + th levels, + C+ 2 are subsets of functonalty artfacts and contracts from the th and + th levels, respectvely. The formula () depcts preservaton of constran dependences between the correspondng artfacts n a transformaton. If a par of artfacts s related at th level, then after transformaton, ther resultng artfacts at (+) th level should also be related. The dentfed phases do not suggest that the process follows the rules of the waterfall process. The successon of phases shown n Fg. focuses on the man dea recognzng the fundamental artfacts of the process. Possble back dependences and the overlappng of phases are omtted n the fgure. The dependences wthn the process, as well as the automated transformaton of functonalty artfacts and contracts support system evoluton, especally for changng busness requrements. Ths corresponds to the ntrnsc postulate of the agle approaches and enterprse system development. In CASD, changes n the functonalty and/or n constrants can be propagated through the approprate process levels. 3 CASD Specalzaton for UML, OCL and C# The general dea of the generc CASD process can be specalzed by applyng varous methods and technques for selected artfacts and ther transformatons. The defnton and mantenance of the constran dependences (Fg.) s mportant for the process realzaton. It s recommended to have a tght couplng between artfacts of the both sdes of the process, preferably tool supported. Otherwse the addtonal overhead and manual effort would dscourage the concurrent development of both types of the artfacts. Moreover, certan contracts mght be easly mssed due to an erroneous omsson by a developer. Another recommendaton s automatng of the ntra-phase transtons and mantenance of the trace dependences.
Towards Specalzaton of the Contract-Aware Software Development Process Fg.. The Contract Aware Software Development process. System models can be desgned n UML, especally class dagrams accompaned by logcal constrants specfyng busness contracts at the model levels [7]. They can be specfed n OCL [4,5]. OCL s a declaratve specfcaton language. OCL expressons can be used for defnng class nvarants, pre- and post-condtons of operatons, and other constrants assocated wth model artfacts. UML s a language that can be appled at dfferent levels of abstracton and used for dfferent purposes. Model refnement towards a selected Doman Language and desred technology can be accomplshed by applcaton of model profles. Apart from model to model transformatons amed at the gradual model refnement, models can be translated nto the source code, or at least to a correct but ncomplete subset of the fnal code. One of many possble solutons, whch can be used for the mplementaton of busness systems, s the C# programmng language.
A. Derezńska and P. Ołtarzewsk A crucal part of such a specalzed CASD process s refnement of UML models and transformaton of OCL nto contracts at the code level. The C# language does not drectly nclude concepts of contracts, but we can utlze the Mcrosoft Code Contract lbrary [9] that mplements contracts. The lbrary ntegrates wth the.net 4.0 platform and supports C# and Vsual Basc programmng languages. The basc part of the lbrary s the Contract class ncludng a set of statc methods that enable descrpton of contracts. Invarants can be specfed for classes, structs and nterfaces. Pre- and post-condtons can be assocated wth constructors, methods, overloaded operators, type conversons and accessor methods of propertes, events and ndexers. A specal statc event defned by the Contract class s called n case of contract nvaldaton. Transformaton of OCL nvarants of classes and pre-, postcondtons specfyng operatons can be based on the delegate concept of C#. The detals of ths transformaton are omtted due to brevty reasons. 4 Transform OCL Fragments nto C# - T.O.F.I.C tool The core part of the CASD process consttutes the transformaton of models and ther contracts nto the executable applcatons ncludng the correspondng contracts. The transformaton should satsfy preservaton of dependences defned n Sec. 2. To put ths nto practce the transformaton should be automated and the modelng actvtes asssted n a frendly manner. The specalzed process can be supported by the T.O.F.I.C. tool (Transform OCL Fragments nto C#) [6]. Ths tool extends the CASE tool - the IBM Ratonal Software Archtect [0] wth the C# modelng and code generaton capabltes. The tool conssts of a set of plug-ns of the Eclpse framework that creates so-called Eclpse feature. The man characterstcs of the prelmnary prototype verson of the tool were descrbed n []. The current verson of T.O.F.I.C...7 was consderably extended n comparson to ts prototype. It covers new functonalty (e.g. most of OCL, many structures of C#, contracts n C#) and mproves ts ergonomc features. The UML profles are used for modelng of Doman-Specfc Languages (DSL), n ths case C# concepts and code mappng unts. The approach could be adjusted to the modelng of varous busness nformaton systems accordng to ther needs. The current verson of T.O.F.I.C. was enhanced wth the profle toolng. It ncludes GUI elements that support vsualzaton and edtng of the stereotyped elements of a model. Rapd prototypng and assgnng of stereotypes to the selected model elements s realzed by the C# Acton Tool (CAT). It extends the palette of modelng menus wth the approprate vew. Varous buttons wth graphcal markers can be used to assgn a selected stereotype and vsualzes ths dstncton n the dagram. The tool also facltates the C# code generaton from a refned UML model and OCL constrants. The generated code s extended wth the C# mplementaton of the standard OCL lbrary. Transformaton of OCL contracts s realzed usng the Vstor desgn pattern. The code generaton s ntated wth the creaton of the Abstract Syntax Tree (AST) of an OCL expresson based on ts text representaton n a model. Next, accordng to the approprate transformaton rule, the nodes of the tree are vst-
Towards Specalzaton of the Contract-Aware Software Development Process ed n a gven order. Durng the tree traversal the correspondng C# code s generated and stored n the related complaton unt. Another new feature, the most sgnfcant n the context of the CASD process, s usage of contracts n the target code of OCL. Expressons of OCL are translated nto the correspondng method calls of the Mcrosoft Code Contracts lbrary [9]. Applcaton of the lbrary benefts from an exstng contract soluton that ntegrates wth the Vsual Studo - the commonly used development framework. However, t has also negatve consequences due to lmtatons of the lbrary. The.NET 4.0 platform supports defnng of contracts and applcaton of the dedcated namespace. Verfcaton of contracts s realzed by the addtonal lbrary that should be nstalled wthn the Mcrosoft Vsual Studo envronment. The lbrary s supported by the tools avalable va a command lne as well as usng a GUI extenson. Contracts are verfed durng a project buldng and n the runtme. A lmtaton of the lbrary concerns reacton to a contract nvaldaton. A default reacton on a rased excepton can be modfed by a developer by mplementng the own class for handlng contracts n the runtme. Furthermore, there s no nformaton whch nstance s responsble for a contract nvaldaton. Therefore the excepton trggers handlng of all delegates assocated wth the excepton. The usablty of the approach, the maturty of the extended tool and the mpact of adoptng contract code generaton n the software development process were evaluated n an experment. The experment was conducted by students of an advanced course of software engneerng. The partcpants of the experment cooperated on the development of a common system, elctng and specfyng requrements of partcular system modules. The system smulated busness and control processes of an arport. The requrement specfcatons took nto account varous system constrants. Next, the constrants were ncluded n the descrpton of use cases. The team members swap the requrement specfcatons among others. UML models were desgned accordng to the obtaned specfcatons. The general models were supplemented wth approprate contracts wrtten n OCL and refned to the C# code models wth assstance of CAT. Then, the C# projects were generated from the refned models by the T.O.F.I.C. tool. The OCL contracts were transformed to the correspondng code usng the Mcrosoft Code Contracts lbrary. In the experment the mpact of the automatc code generaton from models wth contracts to the software development was examned. The results of the experment were evaluated n two ways. The models, other ntermedate artfacts, and fnal applcatons wth tests were examned by hand and usng statc and dynamc verfcaton tools. In addton, the partcpants flled n a questonnare after the experment. The general evaluaton of all results confrmed the mproved consstency between the code and ths level of specfcaton that was expressed n refned models and OCL constrants. In the questonnare, the most of partcpants admtted that they would be utlzng the T.O.F.I.C. tool to a project development n the future, assumng the selected mprovements were ncorporated. The key obstacles of the approach are problems of consstency between prelmnary busness rules descrbed n requrements and use cases on the one hand and contracts at the model level on the other hand, the ncreased effort requred durng refnement of models, and the oblgaton of knowledge of OCL.
A. Derezńska and P. Ołtarzewsk Another alternatve to the process specalzaton could be combnng UML models wth constrants wrtten n a target mplementaton language, e.g. Java or C#. Ths knd of specfcaton of busness rules requres valdaton of constrants at the model level, n order to be of any practcal use. 5 Related Work Desgn by Contract prncples [] are frst of all appled at the code level, as n the Effel language [2]. However, there s a lack of tools dealng wth contracts on both abstract levels, as models and code. There are many tools that support OCL [3,4], but the most of them do not generate code from OCL constrants. In [5] such tools were compared takng nto account ther contract generaton capabltes. All these tools, apart from T.O.F.I.C., generate Java code from OCL. There was announced a vson of a potental, preferred OCL tool, but t s stll a future work [6]. Usng Java as a target language, we can utlze Dresden OCL [7] n a specalzed process wth OCL. Ths tool transforms OCL expressons nto aspects of AspectJ. OCL constrants used n MDE towards Corba and Java can also be found n [8,9]. Support for the C# code generaton has been ncorporated nto several CASE tools, but none of them supports contract-based approach for C# at the generated code level. 6 Conclusons The paper presents an approach that combnes model-drven development prncples wth advantages of contract utlzaton. The approach was appled usng selected modelng, specfcaton and mplementaton languages. The early defnton of contracts, as recommended n the CASD process, focuses the attenton of developers on the constrans and ther verfcaton. They should reflect busness rules of a system. OCL constrants are transformed to code contracts supported by a lbrary n order to move the benefts of desgn by contract approach to the modelng level. The prelmnary experment concludes that the tool supported contract evaluaton combned wth the model-drven methodology could mprove the applcaton accuracy and testablty. The applcablty of the methodology depends strongly on the convenent tool support, whch has to be further enhanced. The crtcal ssues also reman completeness of system constrants mplemented as contracts. As far as the obstacles n the contract utlzaton wth T.O.F.I.C. are concerned, the contract lbrary used n the tool could be substtuted by another contract soluton, or there wll be avalable an mproved verson of the Mcrosoft Code Contracts lbrary. The soluton can be extended wth code generaton from the dynamc models, e.g. state machnes. State nvarants and guard condtons can also be transformed nto the approprate code contracts.
References Towards Specalzaton of the Contract-Aware Software Development Process Meyer, B.: Object-Orented Software Constructon, 2nd Edton. Prentce Hall. (997) 2 France, R., Rumpe, B.: Model-drven Development of Complex Software: A Research Roadmap, In: Proc. of Future of Software Engneerng at ICSE 2007, pp. 37-54. IEEE Soc. (2007) 3 Derezńska, A., Ołtarzewsk, P.: Busness Software Development Process Combnng Model-Drven and Contract-Based Approaches. In: Jałoweck, P., Łuasewcz, P., Orłowsk, A. (eds.) Informaton Systems n Management XI, pp. 7-7. WULS Press, Warsaw (20) 4 Object Constrant Language (OCL) (March 5, 202), http://www.omg.org/spec/ocl/ 5 Warmer, J., Kleppe, A.: The Object Constrant Language: Gettng Your Models Ready for MDA, Addson-Wesley Professonal (2008) 6 Ołtrzewsk, P. Software Development Usng Contracts by Example of the T.O.F.I.C Tool, Master Thess, Inst. of Computer Scence, Warsaw Unv. of Technology (20) (n Polsh) 7 Neumarte, L., Ceponene, L., Vadrckas, G.: Representaton of Busness Rules n UML&OCL Models for Developng Informaton Systems. Strna, J., Persson, A. (eds.) POEM 2008, LNBIP, vol. 5, pp. 82-96. Sprnger (2008) 8 Frankel, S.: Model Drven Archtecture: Applng MDA to Enterprse Computng, Wley Press, Hoboken, NJ. (2003) 9 Mcrosoft Code Contracts (March 5, 202), http://research.mcrosoft.com/en-us/projects/contracts 0 IBM Ratonal Software Archtect (March 5, 202), http://www-0.bm.com/software/awdtools/swarchtect/ Derezńska, A., Ołtarzewsk, P.: Model-Drven Engneerng Support for Buldng C# Applcatons, In: Sobh, T., Ellethy, K. (eds.) Innovatons n Computng Scences and Software Engneerng, pp. 449-454. Sprnger (200) 2 Effel Software: An Effel Tutoral (March 5, 202), http://docs.effel.com/ 3 Chmak-Opoka, J., Demuth, B. et al.: OCL Tools Report Based on the IDE4OCL Feature Model. In: Proc. of Internatonal Workshop on OCL and Textual Modelng, col. Tools Europe (20) 4 Toval, A., Requena, V., Fernandez, J. L.: Emergng OCL tools, Journal of Software and System Modelng, Vol. 2, No. 4, pp. 248-26. Sprnger (2003) 5 Derezńska, A., Ołtarzewsk, P.: Code Generaton of Contracts Usng OCL Tools, In: Borzemsk L. et. al (eds.) Informaton Systems Archtecture and Technology, Web Informaton Systems Engneerng, Knowledge Dscovery and Hybrd Computng, pp. 235-244. Publshng House of Wroclaw Unversty of Technology, Poland (20) 6 Chmak-Opoka, J., Demuth, B.: A Feature Model for an IDE4OCL. In: Proc. of Internatonal Workshop on OCL and Textual Modelng (200) 7 Dresden OCL Contracts (March 5, 202), http://reuseware.org/ndex.php/dresdenocl 8 Coronato, A., De Petro, G.: Formal desgn and mplementaton of constrants n software components. Advances n Engneerng Software, 4, 737-747 (200) 9 Dan, L., Dannng, L.: Applyng Model Drven to Software Development: a Unversty Lbrary Case Study. In: Proc. of the 3rd Internatonal Conference on Communcaton Software and Networks, ICCSN, pp. 79-83. IEEE Comp. Soc. (20)