EMOOSE 2001-2002 Object-Oriented Software Evolution Dr. Tom Mens Programming Technology Lab Vrije Universiteit.

Slides:



Advertisements
Similar presentations
1 A Graph Rewriting Formalism for Object-Oriented Software Evolution Tom Mens FWO Postdoctoral Fellow Programming Technology Lab Vrije.
Advertisements

©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
1 Copyright 1998 by Dragos Manolescu and Joseph W. Yoder Building Frameworks With Patterns “An Active Object-Model For A Dynamic Web-Based Application”
Framework is l Reusable Code, often domain specific (GUI, Net, Web, etc) l expressed as l a set of classes and l the way objects in those classes collaborate.
Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative to refactoring.
Refactoring By: Brian Smith. What is Refactoring? Definition: a change to the internal structure of software to make it easier to understand and cheaper.
© Serge Demeyer, Stéphane Ducasse, Oscar Nierstrasz6.1 Refactorings Refactoring –What is it? –Why is it necessary? –Examples –Tool support Refactoring.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Object-Oriented.
7M701 1 Software Engineering Object-oriented Design Sommerville, Ian (2001) Software Engineering, 6 th edition: Chapter 12 )
Object-Oriented Reengineering Oscar Nierstrasz Software Composition Group University of Bern.
Introduction to Refactoring Excerpted from ‘What is Refactoring?’ by William C. Wake and Refactoring: Improving the Design of Existing Code by Martin Fowler.
1 Objectives To introduces the concept of software Design. To introduce the concept of Object- Oriented Design (OOD). To Define various aspects about object.
REFACTORING Improving the Design of Existing Code Atakan Şimşek e
1 Lecture 5 Introduction to Software Engineering Overview  What is Software Engineering  Software Engineering Issues  Waterfall Model  Waterfall Model.
Software maintenance and evolution Software re-engineering and reverse engineering Prof. Robertas Damaševičius, Prof. Vytautas.
Building software from reusable components.
1 Object-Oriented Software Engineering CIS 375 Bruce R. Maxim UM-Dearborn.
Chapter 9 – Software Evolution and Maintenance
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 14Slide 1 Design with Reuse l Building software from reusable components.
A Survey of Software Refactoring Tom Mens, Tom Tourwé
Object-oriented Software Engineering with Reuse Contracts Koen De Hondt, Carine Lucas, Kim Mens, Tom Mens, Patrick Steyaert, Roel Wuyts Programming Technology.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
Advanced Programing practices
Refactoring Cristescu Marilena. Definitions Loose Usage: Reorganize a program(or something) As a noun: a change made to the internal structure of some.
Teaching material for a course in Software Project Management & Software Engineering – part II.
© S. Demeyer, S. Ducasse, O. Nierstrasz Intro.1 1. Introduction Goals Why Reengineering ?  Lehman's Laws  Object-Oriented Legacy Typical Problems  common.
2000 Advanced OOSA State of the Art on Software Architecture Declarative Meta Programming Session 1: Introduction Nantes, EMOOSE.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Software Refactoring Part I: Introduction Bartosz Walter Advanced Object-Oriented Design Lecture 5.
14-1 © Prentice Hall, 2004 Chapter 14: OOSAD Implementation and Operation Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph.
Refactoring. Mathematics: Factor ● fac·tor – One of two or more quantities that divides a given quantity without a remainder, e.g., 2 and 3 are factors.
A Novel Approach to Architectural Recovery in Evolving Object- Oriented Systems PhD thesis Koen De Hondt December 11, 1998.
Software Design Deriving a solution which satisfies software requirements.
Refactoring An Automated Tool for the Tiger Language Leslie A Hensley
Composition of UML Described Refactoring Rules Presented by Chin-Yi Tsai.
Basic Concepts of Component- Based Software Development (CBSD) Model-Based Programming and Verification.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
PROC-1 1. Software Development Process. PROC-2 A Process Software Development Process User’s Requirements Software System Unified Process: Component Based.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
Internet and Intranet Protocols and Applications Lecture 5a: HTTP Client-Server Design and Implementation February 15, 2005 Arthur Goldberg Computer Science.
A Formal Model for Object-Oriented Software Reuse Kim Mens Programming Technology Lab Vrije Universiteit Brussel FNRS MeetingMay 6th, 1997.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
1 ECE 750 Topic 8 Meta-programming languages, systems, and applications Evolving Object-Oriented Designs with Refactorings – Lance Tokuda and Don Batory.
PC204 Lecture 5 Programming Methodologies Copyright 2000 by Conrad Huang and the Regents of the University of California. All rights reserved.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Refactoring. Mathematics: Factor ● fac·tor – One of two or more quantities that divides a given quantity without a remainder, e.g., 2 and 3 are factors.
Diagnosing Design Problems in Object Oriented Systems Adrian Trifu, Radu Marinescu Proceedings of the 12th IEEE Working Conference on Reverse Engineering.
February, 2000Programming Technology Lab, Vrije Universiteit Brussel Component and Framework Reuse Dr. Tom Mens Programming Technology Lab Vrije Universiteit.
Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
Refactoring. 2 Process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its internal.
 2001 Lodewijk Bergmans University of Twente Pattern Languages.
Presented by: Samia Azhar( ) Shahzadi Samia( )
Reuse Contracts A Historic Overview Dr. Tom Mens Programming Technology Lab Vrije Universiteit Brussel Course OOSE.RC EMOOSE
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
A proposal to support the extreme programming development methodology from the quality assurance point of view Authors: Calin Jebelean –
Object-Oriented Software Engineering Practical Software Development using UML and Java Modelling with Classes.
Refactoring. DCS – SWC 2 Refactoring ”A change made to the internal structure of software to make it easier to understand and cheaper to modify without.
2000 Research Overview Dr. Kim Mens Programming Technology Lab Vrije Universiteit Brussel.
Welcome to OBJECT ORIENTED PROGRAMMING Prepared By Prepared By : VINAY ALEXANDER PGT(CS) KV jhagrakhand.
Principles and examples
Sections Inheritance and Abstract Classes
Authors: Khaled Abdelsalam Mohamed Amr Kamel
A Declarative Evolution Framework for Object-Oriented Design Patterns
Domain Class Diagram Chapter 4 Part 2 pp
Code Smells 1.
Advanced Programming Behnam Hatami Fall 2017.
Advanced Programing practices
Reuse Contracts: Managing the Evolution of Reusable Assets
Refactoring.
Presentation transcript:

EMOOSE Object-Oriented Software Evolution Dr. Tom Mens Programming Technology Lab Vrije Universiteit Brussel Pleinlaan Brussel Belgium Refactoring Basics

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 2 Bibliography - Books  K. Beck. Smalltalk best practice patterns. Prentice Hall,  M. Fowler. Refactoring: improving the design of existing programs. Addison-Wesley, 1999.

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 3 Bibliography – PHD Theses  W. G. Griswold. Program restructuring as an aid to software maintenance. University of Washington, USA, August  W. F. Opdyke. Refactoring object-oriented frameworks. University of Illinois at Urbana-Champaign, USA,  I. Moore. Automatic restructuring of object-oriented programs. Manchester University, UK,  S. Tichelaar. Modeling object-oriented software for reverse engineering and refactoring. PhD Thesis, University of Bern, Switzerland, 2001.

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 4 Bibliography - Articles  P. L. Bergstein. “Maintenance of Object-Oriented Systems During Structural Evolution,” TAPOS Journal 3(3): , 1997  S. Demeyer, S. Ducasse, O. Nierstrasz. Finding refactorings via change metrics. Proc. OOPSLA 2000, ACM Press,  B. Foote, W. F. Opdyke. Life cycle and refactoring patterns that support evolution and reuse,  W. G. Griswold, D. Notkin. Automated assistance for program restructuring. ACM Trans. Software Engineering and Methodology, 2(3): , July  R. E. Johnson, W. F. Opdyke. Refactoring and aggregation,  I. Moore. Automatic inheritance hierarchy restructuring and method refactoring, Proc. Int. Conf. OOPSLA 1996.

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 5 Bibliography – Articles ctd.  W. F. Opdyke, R. E. Johnson. Creating abstract superclasses by refactoring. Proc. ACM Computer Science Conf., pp , ACM Press,  D. Roberts, J. Brant, R. E. Johnson. A refactoring tool for Smalltalk. TAPOS Journal 3(4): ,  S. Tichelaar, S. Ducasse, S. Demeyer, O. Nierstrasz. A Meta-Model for Language-Independent Refactoring,  L. Tokuda, D. Batory. Automated Software Evolution via Design Pattern Transformations. Proc. 3rd Int. Symp. Applied Corporate Computing, October  L. Tokuda, D. Batory. Automating Three Modes of Evolution for Object-Oriented Software Architectures. In 5 th Conference on Object-Oriented Technologies, 1999.

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 6 Basic Issues in refactoring  What is refactoring?  Why should you refactor?  When should you refactor?  Categories of refactorings

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 7 What is refactoring? Life-cycle of object-oriented software development  Three phases [Foote&Opdyke1995]  prototyping  initial development using rapid prototyping and incremental changes  expansion  add new user requirements in the form of classes, operations  consolidation  Reorganise the software to make it more reusable/manageable  Introduce frameworks and design patterns / use refactoring

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 8 What is refactoring?  A refactoring is a software transformation that  preserves the external behaviour of the software  improves the internal structure of the software  Refactoring [Fowler 1999]  [noun] a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behaviour  [verb] to restructure software by applying a series of refactorings without changing its observable behaviour

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 9 Why should you refactor?  To improve the software design  To counter code decay (software aging)  To increase software understandibility  To increase productivity (program faster)  on a long term basis, not on a short term basis  To reduce costs of software maintenance  …

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 10 Why should you refactor?  …  To find bugs and write more robust code  To reduce testing  automatic refactorings are guaranteed to be behaviour- preserving  To prepare for / facilitate future customisations  To turn an OO application into a framework  introduce design patterns in a behaviourally preserving way

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 11 When should you refactor?  Only if you see the need for it  Not on a preset periodical basis  Apply the rule of three  1 st time: implement from scratch  2 nd time: implement something similar by code duplication  3 rd time: do not implement similar things again, but refactor  Refactor when adding new features  Especially if feature is difficult to integrate with the existing code  Refactor during bug fixing  If a bug is very hard to trace, refactor first to make the code more understandable  Refactor during code reviews

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 12 Categories of refactorings  Based on granularity  low-level (primitive) vs high-level (composite) refactorings  Based on programming language  language-specific (e.g. Java, Smalltalk,...)  language-independent (e.g. [Tichelaar&al 2000])  Degree of formality  formal (e.g. [Bergstein 1997])  ad-hoc (e.g. [Fowler 1999])  semi-formal  Degree of automation  fully automated (e.g. [Moore 1996])  interactive (e.g. Refactoring Browser of [Roberts&al 1997])  fully manual (e.g. [Fowler 1999])

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 13 Categories of refactorings  Three categories corresponding to generic design evolutions occuring frequently in OO software systems (according to [Demeyer&al 2000]) 1.Create template methods  split methods into smaller chunks to separate common behaviour from specialised parts so that subclasses can override  used to improve reusability, remove duplicated functionality 2.Optimise class hierarchies  insert or remove classes within a class hierarchy and redistribute the functionality accordingly  used to increase cohesion, simplify interfaces, remove duplicated functionality 3.Incorporate composition relationships  move functionality to (newly created) sibling classes  used to reduce coupling, migrate towards black-box frameworks

EMOOSE, January 2002© Tom Mens, Programming Technology Lab Creating template methods A m { … … } B C D A m { … this.n … } n { } B C n { ;super.n } D separate common behaviour (m) from specialised parts (n)

EMOOSE, January 2002© Tom Mens, Programming Technology Lab Optimising class hierarchies a)Refactor to specialise  improve framework design by decomposing a large, complex class into several smaller classes  the complex class usually embodies both a general abstraction and several different concrete cases that are candidates for specialisation b)Refactor to generalise  identify proper abstractions (e.g. abstract classes) by examining concrete examples and generalising their commonalities

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 16 2.a Refactor to Specialise  Specialise a class by adding subclasses corresponding to the conditions in a conditional expression:  choose a conditional whose conditions suggest subclasses (this depends on the desired abstraction)  for each condition, create a subclass with a class invariant that matches the condition  copy the body of the condition to each subclass, and in each class simplify the conditional based on the invariant that is true for the subclass  specialise some (or all) expressions that create instances of the superclass

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 17 2.a Refactor to Specialise Disk Management for DOS Disk disktype... copyDisk formatDisk Disk Management for DOS &MAC formatDisk self diskType = #MSDOS ifTrue: [.. code1..]. self diskType = #MAC ifTrue: [.. code2..]. Disk Management for DOS & MAC Disk... copyDisk formatDisk... DOSDisk... copyDisk formatDisk... MACDisk... copyDisk formatDisk... Disk... copyDisk formatDisk...

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 18 2.b Refactor to generalise  Abstract classes and frameworks are generalisations  People think concretely, not abstractly  Abstractions are found bottom up, by examining concrete examples first  Generalisation proceeds by:  finding things that are given different names but are really the same (and thus renaming them)  parameterising to eliminate differences  breaking large things into small things so that similar components can be found

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 19 2.b Refactor to generalise concrete class A concrete class B abstraction concrete class Aconcrete class B abstract class X

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 20 2.b Refactor to generalise  Steps to create an abstract superclass  Create a common superclass  Make method signatures compatible  Add method signatures to the superclass  Make method bodies compatible  Make instance variables compatible  Move instance variables to the superclass  Move common code to the abstract superclass

EMOOSE, January 2002© Tom Mens, Programming Technology Lab 21 2.b Refactor to generalise  Example PrintServer print:Boolean FileServer save FileServerPrintServer OutputServer output

EMOOSE, January 2002© Tom Mens, Programming Technology Lab Incorporating composition relationships  Motivation  Inheritance is sometimes overused and incorrectly used in modelling the relationships among classes  Aggregations are another way to model these relationships  Refactorings regarding aggregations  move instance variables/methods from an aggregate class to the class of one of its components  move instance variables/methods from a component class to the aggregate classes that contain components which are instances of the component class  convert a relationship, modelled using inheritance, into an aggregation and vice versa [Johnson&Opdyke1993]

EMOOSE, January 2002© Tom Mens, Programming Technology Lab Incorporating composition relationships  Example  Convert inheritance into aggregation rep Matrix 2DArray SparseMatrix2DArray MatrixRepresentation output Matrix