oorpt object-oriented reengineering patterns and techniques 1. introduction prof. o. nierstrasz

32
OORPT Object-Oriented Reengineering Patterns and Techniques 1. Introduction Prof. O. Nierstrasz

Post on 20-Dec-2015

222 views

Category:

Documents


1 download

TRANSCRIPT

OORPTObject-Oriented Reengineering Patterns and Techniques

1. Introduction

Prof. O. Nierstrasz

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.2

OORPT

Lecturer

Prof. Oscar [email protected]ützenmattstr. 14/103,Tel. 031 631.4618

Assistants Dr. Tudor Gîrba, Adrian Kuhn

Lectures IWI 001, Wednesdays @ 10h15-12h00

Exercises IWI 001, Wednesdays @ 12h00-13h00

WWW www.iam.unibe.ch/~scg/Teaching/OORPT/

Email list www.iam.unibe.ch/mailman/listinfo/oorpt-vorlesung

Text

“Object-Oriented Reengineering Patterns,” Serge Demeyer, Stéphane Ducasse and Oscar Nierstrasz, Morgan Kaufmann and DPunkt, 2002, ISBN 1-55860-639-4.

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.3

Roadmap

> Goals of this course> Why Reengineer?

— Lehman's Laws— Object-Oriented Legacy

> Typical Problems— common symptoms— architectural problems

& refactoring opportunities

> Reverse and Reengineering— Definitions— Techniques— Patterns

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.4

Roadmap

> Goals of this course> Why Reengineer?

— Lehman's Laws— Object-Oriented Legacy

> Typical Problems— common symptoms— architectural problems

& refactoring opportunities

> Reverse and Reengineering— Definitions— Techniques— Patterns

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.5

Goals of this course

We will try to convince you:

> Yes, Virginia, there are object-oriented legacy systems too!

> Reverse engineering and reengineering are essential activities in the lifecycle of any successful software system. (And especially OO ones!)

> There is a large set of lightweight tools and techniques to help you with reengineering.

> Despite these tools and techniques, people must do job and they represent the most valuable resource.

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.6

Course Schedule

Week Date Lesson

1 25-Oct-06 Introduction

2 1-Nov-06 Lab — understanding legacy software

3 8-Nov-06 Presentation of results (all groups)

4 15-Nov-06 Reverse Engineering

5 22-Nov-06 Visualization for Program Understanding

6 29-Nov-06 Design Extraction and Visualization

7 6-Dec-06 Problem Detection and Duplicated Code

8 13-Dec-06 Restructuring

9 20-Dec-06 Lab — using reengineering tools

10 10-Jan-07 Meta-modeling

11 17-Jan-07 Architectural Extraction

12 24-Jan-07 Testing and Migration Strategies

13 31-Jan-07 TBA

14 7-Feb-07 Final Exam

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.7

Email list

Please register yourself in the course mailing list!

https://www.iam.unibe.ch/mailman/listinfo/oorpt-vorlesung

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.8

Roadmap

> Goals of this course> Why Reengineer?

— Lehman's Laws— Object-Oriented Legacy

> Typical Problems— common symptoms— architectural problems

& refactoring opportunities

> Reverse and Reengineering— Definitions— Techniques— Patterns

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.9

What is a Legacy System ?

“legacy”A sum of money, or a specified article, given to another by will; anything handed down by an ancestor or predecessor. — Oxford English Dictionary

so, further evolution and development may be prohibitively expensive so, further evolution and development may be prohibitively expensive

A legacy system is a piece of software that:

• you have inherited, and• is valuable to you.

Typical problems with legacy systems:• original developers not available• outdated development methods used• extensive patches and modifications

have been made• missing or outdated documentation

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.10

Software Maintenance - Cost

requirementdesign

codingtesting

delivery

x 1

x 5

x 10

x 20

x 200

Relative Maintenance EffortBetween 50% and 75% of

global effort is spent on “maintenance” !

Relative Costof Fixing Mistakes

Solution ?• Better requirements engineering?• Better software methods & tools

(database schemas, CASE-tools, objects, components, …)?

Solution ?• Better requirements engineering?• Better software methods & tools

(database schemas, CASE-tools, objects, components, …)?

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.11

Continuous Development

17.4% Corrective(fixing reported errors)

18.2% Adaptive(new platforms or OS)

60.3% Perfective(new functionality)

The bulk of the maintenance cost is due to new functionality even with better requirements, it is hard to predict new functions

The bulk of the maintenance cost is due to new functionality even with better requirements, it is hard to predict new functions

data from [Lien78a]4.1% Other

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.12

Lehman's Laws

A classic study by Lehman and Belady [Lehm85a] identified several “laws” of system change.

Continuing change> A program that is used in a real-world environment must change, or

become progressively less useful in that environment.

Increasing complexity> As a program evolves, it becomes more complex, and extra

resources are needed to preserve and simplify its structure.

Those laws are still applicable…Those laws are still applicable…

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.13

What about Objects ?

Object-oriented legacy systems> = successful OO systems whose architecture and design no longer

responds to changing requirements

Compared to traditional legacy systems> The symptoms and the source of the problems are the same> The technical details and solutions may differ

OO techniques promise better> flexibility, > reusability, > maintainability> …

they do not come for free they do not come for free

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.14

What about Components ?

Components can be very brittle …After a while one inevitably resorts to glue :-)Components can be very brittle …After a while one inevitably resorts to glue :-)

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.15

(*) process-oriented structured methods, information engineering,data-oriented methods, prototyping, CASE-tools – not OO !

Contradiction ? No!• modern methods make it easier to change

... this capacity is used to enhance functionality!

Contradiction ? No!• modern methods make it easier to change

... this capacity is used to enhance functionality!

Modern Methods & Tools ?

[Glas98a] quoting empirical study from Sasa Dekleva (1992)> Modern methods(*) lead to more reliable software> Modern methods lead to less frequent software repair> and ...> Modern methods lead to more total maintenance time

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.16

How to deal with Legacy ?

New or changing requirements will gradually degrade original design… unless extra development effort is spent to adapt the structure

New Functionality

Hack it in ?

• duplicated code• complex conditionals• abusive inheritance• large classes/methods

First …• refactor• restructure• reengineer

Take a loan on your software pay back via reengineeringTake a loan on your software pay back via reengineering

Investment for the future paid back during maintenanceInvestment for the future paid back during maintenance

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.17

Roadmap

> Goals of this course> Why Reengineer?

— Lehman's Laws— Object-Oriented Legacy

> Typical Problems— common symptoms— architectural problems

& refactoring opportunities

> Reverse and Reengineering— Definitions— Techniques— Patterns

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.18

Common Symptoms

Lack of Knowledge> obsolete or no documentation> departure of the original

developers or users> disappearance of inside

knowledge about the system> limited understanding of entire

system missing tests

Lack of Knowledge> obsolete or no documentation> departure of the original

developers or users> disappearance of inside

knowledge about the system> limited understanding of entire

system missing tests

Process symptoms> too long to turn things over to

production> need for constant bug fixes> maintenance dependencies> difficulties separating products

simple changes take too long

Process symptoms> too long to turn things over to

production> need for constant bug fixes> maintenance dependencies> difficulties separating products

simple changes take too long

Code symptoms• duplicated code• code smells

big build times

Code symptoms• duplicated code• code smells

big build times

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.19

Common Problems

Architectural Problems> insufficient documentation

= non-existent or out-of-date> improper layering

= too few or too many layers> lack of modularity

= strong coupling> duplicated code

= copy, paste & edit code> duplicated functionality

= similar functionality by separate teams

Architectural Problems> insufficient documentation

= non-existent or out-of-date> improper layering

= too few or too many layers> lack of modularity

= strong coupling> duplicated code

= copy, paste & edit code> duplicated functionality

= similar functionality by separate teams

Refactoring opportunities> misuse of inheritance

= code reuse vs polymorphism> missing inheritance

= duplication, case-statements> misplaced operations

= operations outside classes> violation of encapsulation

= type-casting; C++ "friends"> class abuse

= classes as namespaces

Refactoring opportunities> misuse of inheritance

= code reuse vs polymorphism> missing inheritance

= duplication, case-statements> misplaced operations

= operations outside classes> violation of encapsulation

= type-casting; C++ "friends"> class abuse

= classes as namespaces

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.20

FAMOOS Case Studies

Different reengineering goals … but common themes and problems !Different reengineering goals … but common themes and problems !

Domain LOC Reengineering Goal

pipeline planning 55,000 extract design

user interface 60,000 increase flexibility

embedded switching

180,000 improve modularity

mail sorting 350,000 portability & scalability

network management

2,000,000 unbundle application

space mission 2,500,000 identify components

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.21

Roadmap

> Goals of this course> Why Reengineer?

— Lehman's Laws— Object-Oriented Legacy

> Typical Problems— common symptoms— architectural problems

& refactoring opportunities

> Reverse and Reengineering— Definitions— Techniques— Patterns

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.22

Some Terminology

“Forward Engineering is the traditional process of moving from high-level abstractions and logical, implementation-independent designs to the physical implementation of a system.”

“Reverse Engineering is the process of analyzing a subject system to identify the system’s components and their interrelationships and create representations of the system in another form or at a higher level of abstraction.”

“Reengineering ... is the examination and alteration of a subject system to reconstitute it in a new form and the subsequent implementation of the new form.”

— Chikofsky and Cross [in Arnold, 1993]

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.23

Goals of Reverse Engineering

> Cope with complexity— need techniques to understand large, complex systems

> Generate alternative views— automatically generate different ways to view systems

> Recover lost information— extract what changes have been made and why

> Detect side effects— help understand ramifications of changes

> Synthesize higher abstractions— identify latent abstractions in software

> Facilitate reuse— detect candidate reusable artifacts and components

— Chikofsky and Cross [in Arnold, 1993]

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.24

Reverse Engineering Techniques

> Redocumentation— pretty printers— diagram generators— cross-reference listing generators

> Design recovery— software metrics— browsers, visualization tools— static analyzers— dynamic (trace) analyzers

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.25

Goals of Reengineering

> Unbundling— split a monolithic system into parts that can be separately

marketed> Performance

— “first do it, then do it right, then do it fast” — experience shows this is the right sequence!

> Port to other Platform— the architecture must distinguish the platform dependent

modules> Design extraction

— to improve maintainability, portability, etc.> Exploitation of New Technology

— i.e., new language features, standards, libraries, etc.

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.26

Reengineering Techniques

> Restructuring— automatic conversion from unstructured to structured code— source code translation

— Chikofsky and Cross

> Data reengineering— integrating and centralizing multiple databases— unifying multiple, inconsistent representations— upgrading data models

— Sommerville, ch 32

> Refactoring — renaming/moving methods/classes etc.

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.27

The Reengineering Life-Cycle

Requirements

Designs

Code

(0) requirementanalysis

(1) modelcapture

(2) problemdetection (3) problem

resolution

(4) program transformation

• people centric• lightweight

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.28

Reverse engineering Patterns

Reverse engineering patterns encode expertise and trade-offs in extracting design from source code, running systems and people.

— Even if design documents exist, they are typically out of sync with reality.

Example: Interview During Demo

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.29

Reengineering Patterns

Reengineering patterns encode expertise and trade-offs in transforming legacy code to resolve problems that have emerged.

— These problems are typically not apparent in original design but are due to architectural drift as requirements evolve

Example: Move Behaviour Close to Data

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.30

A Map of Reengineering Patterns

Tests: Your Life Insurance

Detailed Model Capture

Initial Understanding

First Contact

Setting Direction

Migration Strategies

Detecting Duplicated Code

Redistribute Responsibilities

Transform Conditionals to Polymorphism

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.31

Summary

> Software “maintenance” is really continuous

development

> Object-oriented software also suffers from legacy

symptoms

> Reengineering goals differ; symptoms don’t

> Common, lightweight techniques can be applied to keep

software healthy

© Stéphane Ducasse, Serge Demeyer, Oscar Nierstrasz

OORPT — Introduction

1.32

License

> http://creativecommons.org/licenses/by-sa/2.5/

Attribution-ShareAlike 2.5You are free:• to copy, distribute, display, and perform the work• to make derivative works• to make commercial use of the work

Under the following conditions:

Attribution. You must attribute the work in the manner specified by the author or licensor.

Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one.

• For any reuse or distribution, you must make clear to others the license terms of this work.• Any of these conditions can be waived if you get permission from the copyright holder.

Your fair use and other rights are in no way affected by the above.

Attribution-ShareAlike 2.5You are free:• to copy, distribute, display, and perform the work• to make derivative works• to make commercial use of the work

Under the following conditions:

Attribution. You must attribute the work in the manner specified by the author or licensor.

Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one.

• For any reuse or distribution, you must make clear to others the license terms of this work.• Any of these conditions can be waived if you get permission from the copyright holder.

Your fair use and other rights are in no way affected by the above.