
Coupling, Code Reuse and Open Implementation in Reflective Systems Youssef Hassoun A Thesis Submittrd in Ful¯lment of the Requirements of Doctor of Philosophy in the UNIVERSITY OF LONDON March, 2005 School of Computer Science and Information Systems BIRKBECK COLLEGE Abstract Little research has been conducted in investigating the implications of employ- ing reflection in object-oriented (OO) systems on software qualities such as coupling and reuse. In this thesis, we investigate the reflective capabilities of Java as a rep- resentative of mainstream OO languages and propose a behavioural reflection model, which complements the language's inextensible, introspective, structural reflection model. We show that reflective systems based on the proposed model support the principle of open implementation, and exhibit less coupling and a higher level of code reuse. Programming examples explain how the behaviour of such systems can be customised or adapted without changing their default behaviour or structure. We then show that the model is also applicable to distributed systems allowing for generic coding on the server side. We address the question of assessing coupling and code reuse qualities of reflective systems quantitatively. For this purpose, we de¯ne a dynamic cou- pling metric and a measuring tool that allows the collection of object coupling data at runtime. A case study shows that our coupling metric can be measured automatically and con¯rms the hypothesis about the relatively low coupling of reflective systems in comparison with equivalent systems based on the classi- cal non-reflective programming model. As for code reuse, we de¯ne OO reuse metrics by extending a set of metrics previously developed for procedural lan- guages. A case study is used to con¯rm the hypothesis that reflective systems are more reusable than non-reflective systems exhibiting the same behaviour. Contents 1 Introduction 1 1.1 Problem and motivation . 1 1.2 Thesis objectives and contribution . 4 1.3 Thesis outline . 4 2 Related Work 6 3 Reflection in Java 11 3.1 Reflection . 12 3.2 Proxies . 13 3.3 Structural and Behavioural Reflection Models . 16 3.3.1 Java's introspective structural reflection . 16 3.3.2 A behavioural reflection model based on proxies . 17 3.3.3 Meta-objects as a means of reflection . 18 3.3.4 Comparison with CLOS MOPs . 20 3.4 Open Implementation . 21 3.4.1 Open implementation guidelines . 23 3.4.2 Customising applications' behaviour . 24 3.5 Discussion . 27 3.6 Conclusions . 29 4 Applications of the Reflection Model 32 4.1 Open architecture in a distributed system . 33 4.2 Distributed Applications . 35 4.2.1 RMI-based system . 35 4.2.2 CORBA implementation . 40 4.2.3 Java's Servlets implementation . 45 4.3 Design Patterns . 49 4.3.1 Behavioural Patterns . 50 4.3.2 Structural Patterns . 61 4.3.3 Creational Patterns . 69 4.4 Discussion . 70 4.5 Conclusions . 73 2 CONTENTS 3 5 Coupling Metrics 74 5.1 Software Metrics . 75 5.1.1 Metric scales . 77 5.1.2 Metric validation . 78 5.2 A Dynamic Coupling Metric . 78 5.2.1 DCM scales . 81 5.2.2 Class dependencies and object coupling . 81 5.3 Theoretical Validation of DCM ................... 83 5.3.1 Weyuker's set of measurement principles . 83 5.3.2 Applying Weyuker's principles on DCM . 85 5.3.3 The coupling measures criteria of Briand et al. 89 5.4 On the Empirical Validation of the DCM . 90 5.4.1 Measuring tool . 91 5.4.2 A case study . 93 5.5 Discussion . 100 5.6 Conclusions . 103 6 Code Reuse Metrics 105 6.1 Object-Oriented Code Reuse Measures . 106 6.1.1 Adapting Chen's software model and measures . 107 6.1.2 An illustrative example . 108 6.2 Theoretical Validation of the Metrics . 109 6.3 Empirical Validation: A Case Study . 112 6.3.1 An approach to code reuse . 113 6.3.2 Improving OO code reuse through reflection . 113 6.3.3 Reuse Analysis . 115 6.4 Discussion . 118 6.5 Conclusions . 119 7 Conclusions and future work 120 7.1 Theme and goals of the thesis . 120 7.2 The contribution of the thesis . 120 7.3 Future work . 122 References 124 List of Tables 3.1 ProxyFactory for creating proxy objects . 25 3.2 Example Runtime binding and triggering rei¯cation . 26 3.3 Example Runtime binding and triggering rei¯cation . 27 3.4 Generic implementation of JavaBeans mechanism . 28 4.1 The communication interface between clients and server(s) . 36 4.2 Delegating binding of a base object to ProxyFacory . 37 4.3 The RMI-server process . 39 4.4 The remote interface de¯ning the service protocol . 39 4.5 Remote object wrapper for the Factory class . 40 4.6 A PropertyChangeListener as a client process class . 41 4.7 IDL to support reuse of method invocations over the ORB . 42 4.8 Implementation of the IDL interface ProxyFactoryWrapper . 42 4.9 The CORBA server application . 44 4.10The CORBA client application . 45 4.11Client uses URL objects to communicate with Web-server . 47 4.12Controller servlet provides clients with ActivePropertyHandlers . 48 4.13An implementation of the Template pattern: the meta-program . 51 4.14An implementation of the Template pattern: the client part . 51 4.15The meta-level part of the Strategy pattern implementation . 53 4.16An implementation of the Visitor pattern . 55 4.17An implementation of the Visitor pattern at the meta-level . 56 4.18CommandHandler controls execution of commands . 59 4.19Commands are dispatched to the meta-level using a proxy object 60 4.20A Vector object as adaptee . 61 4.21Adapting default implementation of a stack using a proxy . 62 4.22Adapting default implementation of a stack using a proxy . 64 4.23An implementation of Composite without meta-programming . 65 4.24The meta-level part of the Composite pattern implementation . 68 4.1 Features of design patterns when adapted to the reflection model 72 5.1 Main features of the interceptive code . 94 5.2 Concrete aspect for intercepting executions a concrete system . 95 4 LIST OF TABLES 5 5.1 DCM values as a function of the execution steps of the static model 96 5.2 DCM values as a function of the execution steps of the meta-model 98 6.1 MVC implementation using JavaBeans . 114 6.2 Application classes of the second system . 115 6.1 Entities of both systems and reuse percentages . 116 List of Figures 3.1 Clients request services from Target objects to ful¯l their tasks . 14 3.2 A proxy can manipulate clients' requests before dispatching control 14 3.3 Key classes of dynamic proxies' dispatch mechanism . 15 3.4 A two-level reflective architecture with proxies . 18 4.1 A two-level reflective model with remote proxies . 34 4.2 Class diagram in the distributed RMI environment . 38 4.3 Class structure of the Strategy pattern . 52 4.4 Adapting the Strategy pattern to the reflection model . 53 4.5 Class structure of the Visitor pattern . 55 4.6 Adapting the Visitor pattern to the reflection model . 57 4.7 Class structure of the Composite pattern . 66 4.8 Adapting the Composite pattern to the reflection model . 67 5.1 Class structure of the static system . 96 5.2 Class structure of the dynamic system . 97 5.3 DCM(static system) vs DCM(meta-system) for 1-1000 steps . 99 5.4 DCM(static system) vs DCM(meta-system) for 1-10000 steps . 99 5.5 Static coupling holds a constant contribution to DCM over time . 100 5.6 DCM increases steadily at a constant rate in case of static coupling101 5.7 Transient coupling reduces the number of contributions to DCM . 101 5.8 A variable and slower increase rate in case of transient coupling . 102 6.1 Application S reusing set P . 108 6 Acknowledgements I would like to thank all, who through their support and help have allowed me to bring this work to the end, in particular my supervisors Dr. Roger Johnson and Dr. Steve Counsell for their constant support, encouragement, patience and collaboration. I am grateful to the School of Computer Science and Information Systems at Birkbeck College for the Teaching Assistantship (TA) and the fruitful research atmosphere- Professor George Loizou for his interest and support, and Professor Alexandra Poulovassilis, Head of the School of Computer Science and Informa- tion Systems, for her encouragement and support, Roger Mitton, who managed the TA group, for his excellent leadership and Dr. Constantinos Constantinides for his collaboration at an early stage of my research. Many thanks to the System Group in the School namely Phil Gregg, Phil Docking, Andrew Watkins and Graham Sadler for providing the computing facilities and their friendly and prompt response in case of problems. Mrs Betty Walters and the administrative group for providing an excellent working environment. I would like to thank Professor Laurie Hendren, Professor of Computer Science, McGill University in Canada and Visiting Fellow at Oxford University Computing Laboratory, for her interest in the implementation of measuring tools for collecting coupling data at runtime. I bene¯ted from seminars organised by the British Computer Society (BCS) Advanced Programming Specialist Group. It was an invaluable opportunity to meet and discuss current research topics with the group and with speakers of international pro¯le. In this context, many thanks to my supervisor Dr. Roger Johnson and to all other members of the organising committee especially chairman Professor John Florentin. The research reported in this thesis has bene¯tted from anonymous review- ers. I would like to thank those reviewers, who through their incisive and useful critic have contributed signi¯cantly to improving the submitted papers and consequently the work presented here.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages139 Page
-
File Size-