Com S 362: Object-Oriented Analysis and Design Refactoring.

Slides:



Advertisements
Similar presentations
Module 7. Simplifying Conditional Expressions Course: Refactoring.
Advertisements

Clean code. Motivation Total cost = the cost of developing + maintenance cost Maintenance cost = cost of understanding + cost of changes + cost of testing.
Problem Solving and Algorithm Design
Chapter 6 Problem Solving and Algorithm Design. 6-2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Object-Oriented Databases v OO systems associated with – graphical user interface (GUI) – powerful modeling techniques – advanced data management capabilities.
Encapsulation, Inheritance & Interfaces CSE 115 Spring 2006 February 27, March 1 & 3, 2006.
© 2005 Prentice Hall8-1 Stumpf and Teague Object-Oriented Systems Analysis and Design with UML.
Introduction to Refactoring Excerpted from ‘What is Refactoring?’ by William C. Wake and Refactoring: Improving the Design of Existing Code by Martin Fowler.
George Blank University Lecturer. REFACTORING Improving the Design of Existing Code Supplement to Ian Sommerville, Software Engineering, Chapter 20 Prepared.
7M701 1 Class Diagram advanced concepts. 7M701 2 Characteristics of Object Oriented Design (OOD) objectData and operations (functions) are combined 
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
REFACTORING Improving the Design of Existing Code Atakan Şimşek e
Chapter 1 Principles of Programming and Software Engineering.
Visual Basic Introduction IDS 306 from Shelly, Cashman & Repede Microsoft Visual Basic 5: Complete Concepts and Techniques.
Programming Paradigms cs784(Prasad)L5Pdm1. Programming Paradigm A way of conceptualizing what it means to perform computation and how tasks to be carried.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
Introduction To System Analysis and design
A Survey of Software Refactoring Tom Mens, Tom Tourwé
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
5.1 and 5.4 through 5.6 Various Things. Terminology Identifiers: a name representing a variable, class name, method name, etc. Operand: a named memory.
An Object-Oriented Approach to Programming Logic and Design
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
Advanced Programing practices
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
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.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
17-Oct-15 Refactoring. 2 Refactoring is: restructuring (rearranging) code......in a series of small, semantics-preserving transformations (i.e. the code.
COMP 6471 Software Design Methodologies Winter 2006 Dr Greg Butler
Small changes to code to improve it. Refactoring Defined A change made to the internal structure of software to make it easier to understand and cheaper.
Refactoring1 Refactoring DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY February 6, 2009.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Starting Object Design
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 1 Simplifying Conditionals Steve Chenoweth Office Phone: (812) Cell: (937)
Refactoring1 Improving the structure of existing code.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
CS 4233 Review Feb February Review2 Outline  Previous Business – My.wpi.edu contains all grades to date for course – Review and contact.
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.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Object-Oriented Analysis and Design CHAPTERS 9, 31: DOMAIN MODELS 1.
ITEC324 Principle of CS III Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Com S 362: Object-Oriented Analysis and Design From Design To Code.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 3 Dealing with Generalization Steve Chenoweth Office Phone: (812) Cell: (937)
Com S 362: Object-Oriented Analysis and Design Interaction Diagrams and Responsibility Assignment Oct 23, 2006.
Refactoring1 Improving the structure of existing code.
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.
Software Construction and Evolution - CSSE 375 Simplifying Conditionals Shawn & Steve.
Introduction to Objects and Encapsulation Computer Science 4 Mr. Gerb Reference: Objective: Understand Encapsulation and abstract data types.
Fusion Design Overview Object Interaction Graph Visibility Graph Class Descriptions Inheritance Graphs Fusion: Design The overall goal of Design is to.
Module 9. Dealing with Generalization Course: Refactoring.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Principles of Programming & Software Engineering
Module Road Map Refactoring Why Refactoring? Examples
UML Interaction Diagrams
Overview of Eclipse Lectures
Code Smells 1.
From Design To Code Oct 25, 2006.
Improving the structure of existing code
Interaction Diagrams A Lot of UML!
Advanced Programing practices
Introduction to Methods and Interfaces
Presentation transcript:

Com S 362: Object-Oriented Analysis and Design Refactoring

Com S 362: Object-Oriented Analysis and Design 2 2 Recap: Class Diagrams Class diagrams represent design structure Three parts: name, attribute, operations Visibility, attribute type, multiplicity Association, association multiplicity Generalization i.e. interface impl, subclassing Composition i.e. class A contains class B Applied information hiding, DSM, layering

Com S 362: Object-Oriented Analysis and Design 3 3 Recap: Interaction Diagrams Represent functionality Two major parts: Life line boxes (represent life time of an object) Messages between objects (instances) Also looked at some special case notations Instances: parameterized instances, singleton instances, array elements Messages: creation, destruction, conditional messages, mutually exclusive conditional messages, asynchronous messages, polymorphic messages Abstractions: looping, iteration over collection, nesting of frames, decomposition

Com S 362: Object-Oriented Analysis and Design 4 4 Recap: Responsibility Assignment Information Expert Creator Controller Polymorphism Pure Fabrication Indirection Protected Variations

Com S 362: Object-Oriented Analysis and Design 5 5 Eclipse Tutorial Open source IDE Available from Lot of interesting & advance features Demo: refactoring features in eclipse Extract method Pull up method Push down method

Com S 362: Object-Oriented Analysis and Design 6 6 Refactoring Reorganize instructions in a programs, perhaps rewriting Key: Preserve semantics of the program Objective: Improve structure (aka design), improve readability Doesn’t add/remove any functionality

Com S 362: Object-Oriented Analysis and Design 7 7 Value Argument Refactoring consumes resources Doesn’t add any new feature Impact on near term profit = 0 Why Improve Structure?

Com S 362: Object-Oriented Analysis and Design 8 8 Value Argument Readability More readable less chances of inadvertent errors Adding features in future will be less cumbersome Invest today, reap later Time  Understand- ability Cost/ feature

Com S 362: Object-Oriented Analysis and Design 9 9 Is semantics preserved? Informal & imprecise verification: Write test suite Rigorous test suite development before refactoring Test after you refactor Question: Why do I call it imprecise verification? Formal verification: Prove that certain transformation always preserves the semantics

Com S 362: Object-Oriented Analysis and Design 10 Com S 362: Object-Oriented Analysis and Design 10 Refactoring that you don't see Compiler optimizations Refactoring for performance improvement Example code: radius =..; while(index < Length){ array[index] = 2 * pi * radius; }

Com S 362: Object-Oriented Analysis and Design 11 Com S 362: Object-Oriented Analysis and Design 11 Loop Invariant Optimization radius =..; perimeter = 2 * pi * radius while(index < Length){ array[index] = perimeter; } Compiler optimizations go through precise verification

Com S 362: Object-Oriented Analysis and Design 12 Com S 362: Object-Oriented Analysis and Design 12 Common Refactoring Techniques Extract method Pull up method Push down method Consolidate conditional expressions Encapsulate Collection … Alphabetical list at:

Com S 362: Object-Oriented Analysis and Design 13 Com S 362: Object-Oriented Analysis and Design 13 Extract Method: The Problem Frequent Renter Point Movie Presentation Statement Logic

Com S 362: Object-Oriented Analysis and Design 14 Com S 362: Object-Oriented Analysis and Design 14 Pull Up Method/Field/Constructor Fowler: Refactoring, Page 322 Methods with identical results on subclasses Move the method to superclass

Com S 362: Object-Oriented Analysis and Design 15 Com S 362: Object-Oriented Analysis and Design 15 Push Down Method Behavior on a superclass is relevant only for some of its subclasses. Move the behavior to the subclass Fowler: Refactoring - Page 328

Com S 362: Object-Oriented Analysis and Design 16 Com S 362: Object-Oriented Analysis and Design 16 Consolidate Conditional Expression double disabilityAmount() { if (_seniority < 2) return 0; if (_monthsDisabled > 12) return 0; if (_isPartTime) return 0; // compute the disability amount double disabilityAmount() { if (isNotEligableForDisability()) return 0; // compute the disability amount Fowler: Refactoring - Page 240 Checking Eligibility for disability

Com S 362: Object-Oriented Analysis and Design 17 Com S 362: Object-Oriented Analysis and Design 17 Encapsulate Collection Method returns a collection Breaks encapsulation Allows clients to manipulate collection without objects’ knowledge Make a read-only view, provide methods to add remove elements Fowler: Refactoring - Page 208

Com S 362: Object-Oriented Analysis and Design 18 Com S 362: Object-Oriented Analysis and Design 18 Summary Improve the structure of code No value gain at the moment Easier to add features later Less chances of errors in maintenance tasks Key is to preserve semantics Imprecisely ensure that by developing tests Also, by code inspection

Com S 362: Object-Oriented Analysis and Design 19 Com S 362: Object-Oriented Analysis and Design 19 Exercise Can some refactoring techniques change the design structure matrix view of the system? If yes, which refactoring techniques change the DSM view and how?

Com S 362: Object-Oriented Analysis and Design 20 Com S 362: Object-Oriented Analysis and Design 20