14
F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen, Mentor MITRE/CAASD An Example of Code Refactoring with Legacy Code in a Flight Model Software “The contents of this material reflect the views of the author and/or the Director of the Center for Advanced Aviation System Development. Neither the Federal Aviation Administration nor the Department of Transportation makes any warranty or guarantee, or promise, expressed or implied, concerning the content or accuracy of the views expressed herein”

F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

Embed Size (px)

Citation preview

Page 1: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.

Case #07-1466 Approved for Public Release; Distribution Unlimited.

Eric Shi

H. Peter Stassen, Mentor

MITRE/CAASD

An Example of Code Refactoring with Legacy Code in a Flight

Model Software

“The contents of this material reflect the views of the author and/or the Director of the Center for Advanced Aviation System Development. Neither the Federal Aviation Administration nor the

Department of Transportation makes any warranty or guarantee, or promise, expressed or implied, concerning the content or accuracy of the views expressed herein”

Page 2: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.2 Case #07-1466 Approved for Public Release; Distribution Unlimited.

MITRE/CAASDIntegrated Air Traffic Management (ATM) Lab

• Research from the perspective of National Airspace System (NAS) stakeholders– Flight Crew

– Air Traffic Controllers• Tower

• Terminal

• Enroute

– Air Traffic Managers

• Supports efforts to – Evaluate and mature new concepts

– Study human factors issues

– Build industry consensus

Page 3: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.3 Case #07-1466 Approved for Public Release; Distribution Unlimited.

Integrated ATM Lab Cockpit Simulator

• Simulates a generic air-transport category airplane

• Fixed-base cockpit research simulator

– Medium-fidelity

– Not meant for training, emphasis on research

– Rapid-prototyping capability

– Data collection capability

Page 4: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.4 Case #07-1466 Approved for Public Release; Distribution Unlimited.

Cockpit

• Cockpit simulator: physical cockpit shell

Page 5: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.5 Case #07-1466 Approved for Public Release; Distribution Unlimited.

Flight Model Code Base

• Development began in 1993 using C

– Distributed design (processor limitations)

– Not object oriented

• No comprehensive rework of basic design since inception

• Continual process of modification to add capabilities incrementally

►Code base has become difficult to manage

►Inter-process communications have proliferated

Page 6: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.6 Case #07-1466 Approved for Public Release; Distribution Unlimited.

What is refactoring?

• refactoring (noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior

– Martin Fowler, Refactoring: Improving the Design of Existing Code

• First thesis on refactoring in 1992

• No performance gain

• Only affects those who work directly with the code

• Relevant to systems that employ legacy code

Page 7: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.7 Case #07-1466 Approved for Public Release; Distribution Unlimited.

Benefits of Refactoring

• Easier for programmers to modify and understand

• Cheaper to maintain over time

• Stops the decay of the design as code is changed to realize short-term goals

• Higher quality software

Page 8: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.8 Case #07-1466 Approved for Public Release; Distribution Unlimited.

Project Objectives

• Seeks to apply refactoring principles to the cockpit code

– Move to an object-orientated design using C++

– Employ modern coding standards

– Redesign of code structure

– Take advantage of polymorphism through design patterns

• Behavior of the code remains unchanged

• Combine mode control panel, automatic flight and flight model modules

Page 9: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.9 Case #07-1466 Approved for Public Release; Distribution Unlimited.

Project Methodology

• Literature review

– Refactoring: Improving the Design of Existing Code by Martin Fowler

– Elements of C++ Style by Trevor Misfeldt, Gregory Bumgardner, and Andrew Gray

– Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides

• Cataloging of relevant variables

• Merging into a single module

Page 10: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.10 Case #07-1466 Approved for Public Release; Distribution Unlimited.

Old Flight Model

Flight Model

Mode Control Panel

Automatic Flight

Data

Data

Data

Data

Data

Data

Data

Data

Page 11: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.11 Case #07-1466 Approved for Public Release; Distribution Unlimited.

New Design (Object-Oriented)

Data Classes

Auto Flight

Communications

Navigation

Flight Controls

Flight Model

Atmosphere

Terrain

Engine

Wind

...

...

...

...

...

...

...

...

Simulation Control

Simulation Loop

Page 12: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.12 Case #07-1466 Approved for Public Release; Distribution Unlimited.

New Design

• Elimination of several inter-process communications

• Each component has direct access to data• Extensive usage of the C++ Standard Template

Library– Replacing C constructs with C++ constructs (e.g.

char[] to std::string)

• Class representation of components• Much better maintainability

– Easier to modify, fewer variables through elimination of redundant data

– Easier for others to understand

Page 13: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.13 Case #07-1466 Approved for Public Release; Distribution Unlimited.

Expected Results

• Increased program lifespan

• Accessible to future programmers

• Easier to implement new features

• Easier to apply future refactorings

• Better usage of memory

• Testing by subject-matter experts

Page 14: F053-B08-002 © 2007 The MITRE Corporation. All rights reserved. Case #07-1466 Approved for Public Release; Distribution Unlimited. Eric Shi H. Peter Stassen,

F053-B08-002© 2007 The MITRE Corporation. All rights reserved.14 Case #07-1466 Approved for Public Release; Distribution Unlimited.