void printowing(double amount) { printbanner(); printdetails(); void printdetails(double amount) {

Size: px
Start display at page:

Download "void printowing(double amount) { printbanner(); printdetails(); void printdetails(double amount) {"

Transcription

1 Refactoring References: Martin Fowler, Refactoring: Improving the Design of Existing Code; ; Bruce Wampler, The Essence of Object-Oriented Oriented Programming with Java and UML A recent OO technique that has been formalized into an essential programming tool A technique to improve existing code A technique to improve design after code has been written 1 2 Principles of Refactoring Each change should be a small simple change, followed by testing. Reduces risk that refactoring will cause a problem. Easier to find the problem if it does cause a problem. Functionality remains unchanged Principles of Refactoring Disciplined changes Changes are simple and by themselves of little value. It's the cumulative effects that makes refactoring valuable. 3 4 Testing and Refactoring Build test cases first that will verify the external behavior. You don't want to change external behavior. Automated tests are important. Self-checking is important. Benefit of Refactoring Makes it easier to fix bugs and add features to code Can reveal flaws in structure of existing code that are causes of bugs 5 6 1

2 Refactoring Process When to Refactor Study the known refactorings that have been described by Fowler in Refactoring: Improving the Design of Existing Code (Addison Wesley,2000) Review code to identify refactorings Apply only one refactoring at a time reduces risk of making changes Test the program after each refactoring 7 When you plan to add functionality to the program When you find you have to add a feature to a program, and the program s code is not structured in a convenient way to add the feature, first refactor the program to make it easier to add the feature, then add the feature. [Fowler,7] Apply refactoring until design has improved enough to make it easily modifiable 8 When to Refactor Code Smells When searching for bugs During code reviews teams refactor as the group gets better understanding of the code Fowler and Kent Beck have identified smells in code that, when present, indicate you should refactor The following is a subset of their list of code smells 9 10 Code Smells Code Smells Duplicate code you need to extract some methods Long method long methods are hard to understand; extract methods Large class if a class does too much, you need to split it Long parameter list makes code hard to read consider passing objects Feature envy one class is interested in too many details of another class [Fowler] Data clumps data that is used together everywhere should be in a class of its own [Fowler]

3 Code Smells Switch statements you aren t using polymorphism effectively Inappropriate intimacy a class shouldn t know too much about any other class Data class a class needs to do something, not just maintain attributes Code Smells Refused bequest subclasses should use most of what their parents give them [Fowler] Comments a comments might be eliminated by providing a better name for a method or variable Code Smells Message chain too many messages in a chain are hard to follow [Fowler] Middleman sometimes it s better to work with an object directly [Fowler] When not to Refactor When code is beyond fixing and needs to be rewritten from scratch When program is written in a non-oo language Refactoring Categories Over 70 refactorings are described in Fowler s book Refactorings are organized into categories A sampling of the categories follows Each category includes a number of refactorings; these are in italics Composing Methods Help to reduce size of methods and make code more readable by replacing sequences of code with method calls Extract Method Inline Method Replace Temp with Query

4 Moving Features Between Objects Take responsibilities away from classes that shouldn t have them and put the responsibilities where they belong Move Method Move Field Extract Class Organizing Data Make objects from data items to clarify what the data item is being used for and to make it easier to work with Replace Data Value with Objects Replace Array with Object Simplifying Conditional Expressions Simplify complicated conditional expressions that make program hard to understand Decompose Conditional Consolidate Duplicate Conditional Fragments Replace Conditional with Polymorphism Making Method Calls Simpler Improve the interface to a class by making method names clearer and more descriptive Rename Method Add parameter Dealing with Generalization Move methods and subclasses as high up the inheritance hierarchy as possible for good object design Pull Up Method Push Down Method Extract Subclass Extract Superclass Refactorings in Detail Some refactorings with more detailed explanation and examples are discussed next

5 Extract Method When a code fragment has meaning by itself, it can be refactored as a method The method name should clearly explain the purpose of the method (this eliminates need for a comment) Duplicated code belongs in a method Extract Method Example[Fowler,110] void printowing(double amount) { printbanner(); //print details System.out.println( name: + name); System.out.println( amount + amount); void printowing(double amount) { printbanner(); printdetails(); void printdetails(double amount) { System.out.println( name: + name); System.out.println( amount + amount); Replace Temp With Query When a temporary variable is being used to hold the result of an expression, extract the expression into a method and replace all references to the temp variable with the method call Replace Temp With Query Example [Fowler,120] double baseprice = quantity * itemprice; if(baseprice > 1000) return baseprice * 0.95; else return baseprice * 0.98; if (baseprice() > 1000) return baseprice() * 0.95; else return baseprice() * 0.98; double baseprice() { return quantity * itemprice; Rename Method Rename Method Example [Fowler,274] This one is fairly obvious When the name of a method does not reveal its purpose, change the name of the method Methods should be named in a way that communicates their intention. Good naming is a skill that requires practice; improving this skill is the key to being a truly skillful programmer. [Fowler,273] 29 A method to get a person s telephone number can be defined as: public String gettelephonenumber() { return ( ( + officeareacode + ) + officenumber); Since the office number is desired, rename the method to getofficetelephonenumber 30 5

6 Rename Method Example(cont d ) Rename Method Example(end) Create the new method and copy the body over to the new method The old method changes to call the new one class Person public String gettelephonenumber() { return getofficetelephonenumber(); public String getofficetelephonenumber() { return ( ( + officeareacode + ) + officenumber); 31 Now find the callers of the old method (if client code available) and switch them to call the new one When all are switched, remove the old method If there aren t many callers, you can change callers to call the new method without first delegating the call to the old method. But the safest way is to use the delegation. 32 Pull Up Method If you have methods with identical results on subclasses, then move them to the superclass Pull Up Method Example [Fowler,324] RegularCustomer createbill(date) chargefor(start:date,end:date) Customer addbill(dat:date,amount:double) lastbilldate createbill method is identical for each class PreferredCustomer createbill(date) chargefor(start:date,end:date) void createbill(date date) { double chargeamount = chargefor(lastbilldate, date); addbill( date, charge ); Pull Up Method Example (cont d) createbill can t be moved into the superclass because chargefor is different on each subclass First have to declare it on the superclass as abstract Pull Up Method Example(result) Customer lastbilldate addbill(dat:date,amount:double) createbill(date) chargefor(start:date,end:date) class Customer... abstract double chargefor(date start, Date end) Then copy createbill from each of the subclasses, compile and test RegularCustomer chargefor(start:date,end:date) PreferredCustomer chargefor(start:date,end:date)

7 Pull Up Constructor Body You have constructors on subclasses with mostly identical bodies [Fowler,325] Can t use Pull Up Method because you can t inherit constructors Create a superclass constructor; call this from the subclass methods. [Fowler,325] Pull Up Constructor Body Example [Fowler,326] class Employee... protected String _name; protected String _id; class Manager extends Employee... public Manager(String name, String id, int grade){ _name = name; _id = id; _grade = grade; private int _grade; Define a constructor for Employee that can be called by a Manager object Pull Up Constructor Body Example class Employee... protected String _name; protected String _id; protected Employee (String name, String id) { _name = name; _id = id; class Manager... public Manager (String name, String id, int grade) { super (name, id); _grade = grade; Replace Conditional With Polymorphism You have a conditional that chooses different behavior depending on the type of an object. Move each leg of the conditional to an overriding method in a subclass. Make the original method abstract. [Fowler,255] Must have inheritance structure already in place Replace Conditional With Polymorphism double getspeed() { switch (_type) { case EUROPEAN: return getbasespeed(); case AFRICAN: return getbasespeed() - getloadfactor() * _numberofcoconuts; case NORWEGIAN_BLUE: return(_isnailed)? 0 : getbasespeed(_voltage); throw new RuntimeException( Should be reachable ); //[Fowler,255] Replace Conditional With Polymorphism European getspeed() Bird getspeed() NorwegianBlue getspeed() African getspeed() Three subclasses of Bird are created from the conditional. Each overrides the getspeed() method

8 Replace Conditional With Polymorphism Bad idea to do a switch based on attribute of another object If using a switch, it should be on your own data, not another object s Example of this on next slide 43 Replace Conditional With Polymorphism class Rental double { Indicates that getcharge double result = 0; should move into Movie switch(getmovie().getpricecode() ())) { case Movie.REGULAR: result += 2; if(getdaysrented() () > 2) result += (getdaysrented() - 2) * 1.5; case Movie.NEW_RELEASE: result += getdaysrented() * 3; case Movie.CHILDRENS: result += 1.5; if (getdaysrented() > 3) result += (getdaysrented() getdaysrented()-3) * 1.5; return result; 44 Replace Conditional With Polymorphism Replace Conditional With Polymorphism class Movie double getcharge(int daysrented) { double result = 0; switch(getpricecode() ())) { case Movie.REGULAR: result += 2; if(daysrented() > 2) result += (daysrented() case Movie.NEW_RELEASE: Now querying our own data () - 2) * 1.5; result += daysrented() * 3; case Movie.CHILDRENS: result += 1.5; if (daysrented() > 3) result += (daysrented() daysrented()-3) * 1.5; return result; 45 Next compile the method into Movie and then change the getcharge on rental to use the new method class Rental... double getcharge() { return _movie.getcharge(daysrented); 46 Replace Conditional With Polymorphism Several types of movies have different ways of answering the same question This is a job for subclasses Each subclass of Movie has its own version of charge (ie regular, children s, new releases, etc.) Replace Conditional With Polymorphism RegularMovie Movie ChildrensMovie NewReleaseMovie Still need one more change. A movie can change classification during its lifetime. An object cannot change its class during its lifetime. Therefore, need the State pattern [GoF]

9 Replace Conditional With Polymorphism : Using State Pattern Encapsulate the state-specific specific behavior into separate objects and have the context delegatestate-specific specific requests to these objects. Using the State Pattern on Movie Movie RegularPrice 1 Price ChildrensPrice NewReleasePrice return price. Subclassing is done from price code object. Price can be changed whenever necessary Replace Conditional With Polymorphism : Motivation Biggest gain from polymorphism occurs when same set of conditions appears many places in the program To add a new type, you have to find and update all the conditionals But with subclasses you simply create a new subclass and provide the appropriate methods Clients of the class don t need to know about the subclasses, which reduces the coupling in your system [Fowler,256] 51 Decompose Conditional You have a complicated conditional (if- then-else) else) statement. Extract methods from the condition, then part, and else parts. [Fowler,238] Highlight the condition and make clear what you re branching on, and highlight reason for branching. 52 Decompose Conditional Decompose Conditional if ( date.before (SUMMER_START) date.after (SUMMER_END) ) charge = quantity * _winterrate + _winterservicecharge; else charge = quantity * _summerrate; if ( notsummer ( date ) ) charge = wintercharge ( quantity ); else charge = summercharge ( quantity ); Example continued: private boolean notsummer( Date date ) { return date.before (SUMMER_START) date.after (SUMMER_END); private double summercharge (int quantity) { return quantity * _summerrate; private double wintercharge (int quantity) { return quantity * _winterrate + _winterservicecharge; 53 Each extraction should be done separately, then compiled & tested 54 9

10 Consolidate Conditional Expression You have a sequence of conditional tests with the same result. Combine them into a single conditional expression and extract it. [Fowler,240] Makes check clearer Replaces statement of what you re doing with why you re doing it. Must first make sure none of the conditionals has side effects. Consolidate Conditional Expression double disabilityamount () { if (_seniority < 2 ) return 0; if (_monthsdisabled > 12 ) return 0; if (_isparttime) return 0; //compute disability amount double disabilityamount () { if (isnoteligiblefordisability () ) return 0; //compute disability amount Consolidate Conditional Expression if (onvacation() ) if (lengthofservice () > 10 ) return 1; return 0.5; if (onvacation () && length)fservice () > 10 ) return 1; else return 0.5; return (onvacation () && lengthof Service () > 10? 1 : 0.5; 57 10

Credit where Credit is Due. Lecture 25: Refactoring. Goals for this lecture. Last Lecture

Credit where Credit is Due. Lecture 25: Refactoring. Goals for this lecture. Last Lecture Credit where Credit is Due Lecture 25: Refactoring Kenneth M. Anderson Object-Oriented Analysis and Design CSCI 6448 - Spring Semester, 2002 Some of the material for this lecture and lecture 26 is taken

More information

Refactoring. Refactoring. Refactoring. Refactoring. Refactoring. Refactoring. Lesson Five: Conditionals

Refactoring. Refactoring. Refactoring. Refactoring. Refactoring. Refactoring. Lesson Five: Conditionals Lesson Five: should not be too complex. If they are complex, refactor them to make simple methods making readability and understandability better. Learning objective have simple conditionals which are

More information

Evolving Software. CMSC 433 Programming Language Technologies and Paradigms Spring Example. Some Motivations for This Refactoring

Evolving Software. CMSC 433 Programming Language Technologies and Paradigms Spring Example. Some Motivations for This Refactoring CMSC 433 Programming Language Technologies and Paradigms Spring 2007 Refactoring April 24, 2007 Lots of material taken from Fowler, Refactoring: Improving the Design of Existing Code 1 Evolving Software

More information

Refactoring. Section (JIA s) OTHER SOURCES

Refactoring. Section (JIA s) OTHER SOURCES Refactoring Section 7.2.1 (JIA s) OTHER SOURCES Code Evolution Programs evolve and code is NOT STATIC Code duplication Outdated knowledge (now you know more) Rethink earlier decisions and rework portions

More information

Refactoring. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 11/29/11. University of Colorado, 2011

Refactoring. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 11/29/11. University of Colorado, 2011 Refactoring Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 11/29/11 University of Colorado, 2011 Credit where Credit is Due Some of the material for this lecture is taken

More information

Administrivia. Programming Language Fall Example. Evolving Software. Project 3 coming out Midterm October 28. Refactoring October 14, 2004

Administrivia. Programming Language Fall Example. Evolving Software. Project 3 coming out Midterm October 28. Refactoring October 14, 2004 CMSC 433 Programming Language Fall 2004 Project 3 coming out Midterm October 28 Administrivia Refactoring October 14, 2004 Lots of material taken from Fowler, Refactoring: Improving the Design of Existing

More information

Refactoring. Chen Tang March 3, 2004

Refactoring. Chen Tang March 3, 2004 Refactoring Chen Tang March 3, 2004 What Is Refactoring (Definition) Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet

More information

Refactoring. Refactoring Techniques

Refactoring. Refactoring Techniques Refactoring Refactoring Techniques Code Quality is Important! Refactoring is... A disciplined technique for restructuring an existing body of code, altering its internal structure without changing its

More information

Refactoring Exercise

Refactoring Exercise Refactoring Exercise Maria Grazia Pia INFN Genova, Italy Maria.Grazia.Pia@cern.ch http://www.ge.infn.it/geant4/training/apc2017/ Exercise: The Video Store Grab basic concepts Get into the habit of refactoring

More information

Refactoring. Software Engineering, DVGC18 Faculty of Economic Sciences, Communication and IT Eivind Nordby

Refactoring. Software Engineering, DVGC18 Faculty of Economic Sciences, Communication and IT Eivind Nordby Refactoring Faculty of Economic Sciences, Communication and IT 2011-09-21 Why Refactor Refactoring is one factor in keeping your system in shape Without continuous refactoring, the system will rot It takes

More information

COURSE 11 DESIGN PATTERNS

COURSE 11 DESIGN PATTERNS COURSE 11 DESIGN PATTERNS PREVIOUS COURSE J2EE Design Patterns CURRENT COURSE Refactoring Way refactoring Some refactoring examples SOFTWARE EVOLUTION Problem: You need to modify existing code extend/adapt/correct/

More information

Refactoring. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 04/19/11. University of Colorado, 2011

Refactoring. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 04/19/11. University of Colorado, 2011 Refactoring Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 04/19/11 University of Colorado, 2011 Credit where Credit is Due Some of the material for this lecture is taken

More information

Chapter 7: Simplifying Conditional Expressions

Chapter 7: Simplifying Conditional Expressions Chapter 7: Simplifying Conditional Expressions Conditional logic has a way of getting tricky, so here are a number of refactorings you can use to simplify it. The core refactoring here is Decompose Conditional

More information

Refactoring: Improving the Design of Existing Code

Refactoring: Improving the Design of Existing Code Refactoring: Improving the Design of Existing Code Martin Fowler fowler@acm.org www.martinfowler.com www.thoughtworks.com What is Refactoring A series of small steps, each of which changes the program

More information

Badge#8: Geek Refactoring

Badge#8: Geek Refactoring Badge#8: Geek Refactoring Nuno Pombo, Qualidade de Software, 2018/19 1 When To Refactor? Rule of Three When adding a feature When fixing a bug During a code review 2 How To Refactor? The code should become

More information

Patterns in Software Engineering

Patterns in Software Engineering Patterns in Software Engineering Lecturer: Raman Ramsin Lecture 10 Refactoring Patterns Part 1 1 Refactoring: Definition Refactoring: A change made to the internal structure of software to make it easier

More information

Refactoring, Part 2. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 12/01/09. University of Colorado, 2009

Refactoring, Part 2. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 12/01/09. University of Colorado, 2009 Refactoring, Part 2 Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 27 12/01/09 University of Colorado, 2009 1 Introduction Credit where Credit is Due Some of the material for

More information

AntiPatterns. EEC 421/521: Software Engineering. AntiPatterns: Structure. AntiPatterns: Motivation

AntiPatterns. EEC 421/521: Software Engineering. AntiPatterns: Structure. AntiPatterns: Motivation AntiPatterns EEC 421/521: Software Engineering Definition: An AntiPattern describes a commonly occurring solution to a problem that generates decidedly negative consequences Refactoring Reference: Refactoring

More information

Understading Refactorings

Understading Refactorings Understading Refactorings Ricardo Terra terra@dcc.ufmg.br Marco Túlio Valente mtov@dcc.ufmg.br UFMG, 2010 UFMG, 2010 Understanding Refactorings 1 / 36 Agenda 1 Overview 2 Refactoring 3 Final Considerations

More information

Introduction to Refactoring

Introduction to Refactoring Introduction to Refactoring Sutee Sudprasert 1 Credits Refactoring : Improving the design of existing code - Martin Fowler Design Patterns - GOF 2 What is refactoring? Refactoring is the process of changing

More information

Code Refactoring. CS356 Object-Oriented Design and Programming November 21, 2014

Code Refactoring. CS356 Object-Oriented Design and Programming   November 21, 2014 Code Refactoring CS356 Object-Oriented Design and Programming http://cs356.yusun.io November 21, 2014 Yu Sun, Ph.D. http://yusun.io yusun@csupomona.edu The Problem: Software Drift Over many phases of maintenance,

More information

Lecture 12, part 2: Refactoring. NCCU Fall 2005 Dec. 13, 2005

Lecture 12, part 2: Refactoring. NCCU Fall 2005 Dec. 13, 2005 Lecture 12, part 2: Refactoring NCCU Fall 2005 Dec. 13, 2005 1 Refactoring 什? 不 行 理 降 行 不 Unit Testing! Martin Fowler (and Kent Beck, John Brant, William Opdyke, Don Roberts), Refactoring- Improving the

More information

Refactoring. Joseph W. Yoder. The Refactory, Inc. The Refactory Principals.

Refactoring. Joseph W. Yoder. The Refactory, Inc.  The Refactory Principals. Refactoring Joseph W. Yoder The Refactory, Inc. joe@refactory.com http://www.refactory.com The Refactory Principals John Brant Don Roberts Brian Foote Joe Yoder Ralph Johnson Refactory Affiliates Joseph

More information

Refactoring. Paul Jackson. School of Informatics University of Edinburgh

Refactoring. Paul Jackson. School of Informatics University of Edinburgh Refactoring Paul Jackson School of Informatics University of Edinburgh Refactoring definition Refactoring (noun) is a change made to the internal structure of software to make it easier to understand,

More information

Example of OO Design Refactoring

Example of OO Design Refactoring Example of OO Design Refactoring Robert B. France Colorado State University Fort Collins Colorado Robert B. France 1 What is design refactoring? Often an initial design is not a good design Design may

More information

Refactoring. So#ware Quality Quality Audit and Cer4fica4on. Master in Computer Engineering. Roberto García

Refactoring. So#ware Quality Quality Audit and Cer4fica4on. Master in Computer Engineering. Roberto García Refactoring So#ware Quality Quality Audit and Cer4fica4on Master in Computer Engineering Roberto García (rgarcia@diei.udl.cat) Introduc4on When considering soaware evolu4on, the key dis4nc4on is: Program's

More information

Composing Methods. Extract Method - Code that can be grouped - Meaningful name for method

Composing Methods. Extract Method - Code that can be grouped - Meaningful name for method Composing Methods Extract Method - Code that can be grouped - Meaningful name for method Inline Method - inverse of Extract Method - Method body is more obvious Extract Variable - Expression: hard to understand

More information

Refactoring. Thierry Sans. with slides from Anya Tafliovich

Refactoring. Thierry Sans. with slides from Anya Tafliovich Refactoring Thierry Sans with slides from Anya Tafliovich Composing Methods Extract Method void printowing() { printbanner(); //print details System.out.println("name: " + name); System.out.println("amount:

More information

MSO Refactoring. Hans Philippi. October 2, Refactoring 1 / 49

MSO Refactoring. Hans Philippi. October 2, Refactoring 1 / 49 MSO Refactoring Hans Philippi October 2, 2018 Refactoring 1 / 49 This lecture What is refactoring?... or how to deal with the horrible code your colleagues have created... or how to deal with the horrible

More information

CISC327 - Software Quality Assurance

CISC327 - Software Quality Assurance CISC327 - Software Quality Assurance Lecture 19 0 (23 in 2017) Code Inspection in XP CISC327-2003 2018 J.R. Cordy, S. Grant, J.S. Bradbury, J. Dunfield 19 0 say what My next surgery is scheduled for Nov.

More information

Small changes to code to improve it

Small changes to code to improve it Small changes to code to improve it 1 Refactoring Defined A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior

More information

Refactoring. In essence we improve the design of the code after it has been written. That's an odd turn of phrase.

Refactoring. In essence we improve the design of the code after it has been written. That's an odd turn of phrase. Refactoring Process of changing software in such a way that it does not alter the external behavior of the code yet improves its internal structure. Disciplined way to clean up code that minimizes the

More information

The Benefits And Reasons for Doing Refactoring

The Benefits And Reasons for Doing Refactoring The Benefits And Reasons for Doing Refactoring CSC508 Software Engineering by Magnus Aase December 11, 2001 The people behind the work of Refactoring seem all to agree on that Refactoring is not a cure

More information

Refactoring 101. By: Adam Culp

Refactoring 101. By: Adam Culp By: Adam Culp Twitter: @adamculp https://joind.in/14927 2 About me PHP 5.3 Certified Consultant at Zend Technologies Organizer SoFloPHP (South Florida) Organized SunshinePHP (Miami) Long distance (ultra)

More information

CSE 403 Lecture 21. Refactoring and Code Maintenance. Reading: Code Complete, Ch. 24, by S. McConnell Refactoring, by Fowler/Beck/Brant/Opdyke

CSE 403 Lecture 21. Refactoring and Code Maintenance. Reading: Code Complete, Ch. 24, by S. McConnell Refactoring, by Fowler/Beck/Brant/Opdyke CSE 403 Lecture 21 Refactoring and Code Maintenance Reading: Code Complete, Ch. 24, by S. McConnell Refactoring, by Fowler/Beck/Brant/Opdyke slides created by Marty Stepp http://www.cs.washington.edu/403/

More information

Software Design COSC 4353/6353 D R. R A J S I N G H

Software Design COSC 4353/6353 D R. R A J S I N G H Software Design COSC 4353/6353 D R. R A J S I N G H Week 5 Refactoring What is Refactoring? Code Smells Why Refactoring? Techniques IDEs What is Refactoring? Art of improving the design of existing code

More information

More on Design. CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson

More on Design. CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson More on Design CSCI 5828: Foundations of Software Engineering Lecture 23 Kenneth M. Anderson Outline Additional Design-Related Topics Design Patterns Singleton Strategy Model View Controller Design by

More information

Objectives: On completion of this project the student should be able to:

Objectives: On completion of this project the student should be able to: ENGI-0655/5232 Software Construction and Evolution Project 1 Reverse Engineering Refactoring & Object Oriented Design Due date November 10, 2009-4:00 pm 1. Aims The aim of this project is to give you more

More information

Implementing evolution: Refactoring

Implementing evolution: Refactoring 2IS55 Software Evolution Sources Implementing evolution: Refactoring Alexander Serebrenik / SET / W&I 17-5-2010 PAGE 1 Last week Problem: changing code is difficult Assignment 6 Deadline: Today Assignment

More information

Refactoring. What to refactor Refactor to what How to conduct the refactoring. This website is also very informative

Refactoring. What to refactor Refactor to what How to conduct the refactoring. This website is also very informative Refactoring What to refactor Refactor to what How to conduct the refactoring This website is also very informative https://refactoring.com/catalog/ Definitions Changing/improving the code structure w/o

More information

Refactoring. George Dinwiddie idia Computing, LLC

Refactoring. George Dinwiddie idia Computing, LLC Refactoring George Dinwiddie idia Computing, LLC http://idiacomputing.com http://blog.gdinwiddie.com What is Refactoring? Refactoring is a disciplined technique for restructuring an existing body of code,

More information

F. Tip and M. Weintraub REFACTORING. Thanks go to Andreas Zeller for allowing incorporation of his materials

F. Tip and M. Weintraub REFACTORING. Thanks go to Andreas Zeller for allowing incorporation of his materials F. Tip and M. Weintraub REFACTORING Thanks go to Andreas Zeller for allowing incorporation of his materials TODAY S LECTURE anti-patterns common response to a recurring problem that is usually ineffective

More information

Refactorings. Refactoring. Refactoring Strategy. Demonstration: Refactoring and Reverse Engineering. Conclusion

Refactorings. Refactoring. Refactoring Strategy. Demonstration: Refactoring and Reverse Engineering. Conclusion Refactorings Refactoring What is it? Why is it necessary? Examples Tool support Refactoring Strategy Code Smells Examples of Cure Demonstration: Refactoring and Reverse Engineering Refactor to Understand

More information

Keywords Code clean up, code standard, maintainability, extendibility, software refactoring, bad smell code.

Keywords Code clean up, code standard, maintainability, extendibility, software refactoring, bad smell code. Volume 7, Issue 5, May 2017 ISSN: 2277 128X International Journal of Advanced Research in Computer Science and Software Engineering Research Paper Available online at: www.ijarcsse.com A Review on Bad

More information

Refactoring, 2nd Ed. A love story. Michael Hunger

Refactoring, 2nd Ed. A love story. Michael Hunger Refactoring, 2nd Ed. A love story Michael Hunger Michael Hunger Open Sourcerer Neo4j @mesirii It crashed at 940! I know what you're here for! Covers By: dev.to/rly Which Refactoring do you like most? Extract

More information

CS247. Today s topics. Design matters. What is refactoring?

CS247. Today s topics. Design matters. What is refactoring? Today s topics CS247 Refactoring Adapted from Martin Fowler s text and Mike Godfrey s slides. What is refactoring and why do we care? The rule of three. A simple case study that applies some refactorings.

More information

McCa!"s Triangle of Quality

McCa!s Triangle of Quality McCa!"s Triangle of Quality Maintainability Portability Flexibility Reusability Testability Interoperability PRODUCT REVISION PRODUCT TRANSITION PRODUCT OPERATION Correctness Usability Reliability Efficiency

More information

Software Engineering Refactoring

Software Engineering Refactoring Software Engineering Refactoring Software Engineering 2012-2013 Department of Computer Science Ben-Gurion university Based on slides of: Mira Balaban Department of Computer Science Ben-Gurion university

More information

JUnit 3.8.1, 64. keep it simple stupid (KISS), 48

JUnit 3.8.1, 64. keep it simple stupid (KISS), 48 Index A accessor methods, 11, 152 add parameter technique, 189 190 add() method, 286 287, 291 algorithm, substituting, 104 105 AND logical operator, 172 architectural design patterns, 277 278 architecture,

More information

Lecture Notes. Polymorphism. Polymorphism. If Polymorphism is Not Available. To be placed at:

Lecture Notes. Polymorphism. Polymorphism. If Polymorphism is Not Available. To be placed at: To be placed at: Lecture Notes www.cs.umb.edu/~jxs/courses/cs40 Polymorphism Polymorphism If Polymorphism is Not Available Customer gettotaltax():float * Account accounts # balance: float getbalance():

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

EINDHOVEN UNIVERSITY OF TECHNOLOGY

EINDHOVEN UNIVERSITY OF TECHNOLOGY EINDHOVEN UNIVERSITY OF TECHNOLOGY Department of Mathematics & Computer Science Exam Programming Methods, 2IP15, Wednesday 17 April 2013, 09:00 12:00 TU/e THIS IS THE EXAMINER S COPY WITH (POSSIBLY INCOMPLETE)

More information

COURSE 2 DESIGN PATTERNS

COURSE 2 DESIGN PATTERNS COURSE 2 DESIGN PATTERNS CONTENT Fundamental principles of OOP Encapsulation Inheritance Abstractisation Polymorphism [Exception Handling] Fundamental Patterns Inheritance Delegation Interface Abstract

More information

CSCD01 Engineering Large Software Systems. Refactoring. Joe Bettridge. Winter With thanks to Anya Tafliovich (Based on Refactoring by M.

CSCD01 Engineering Large Software Systems. Refactoring. Joe Bettridge. Winter With thanks to Anya Tafliovich (Based on Refactoring by M. CSCD01 Engineering Large Software Systems Refactoring Joe Bettridge Winter 2018 With thanks to Anya Tafliovich (Based on Refactoring by M. Fowler) What is Refactoring? Process of changing a software system

More information

CLEAN CODE, CODE SMELLS, REFACTORING

CLEAN CODE, CODE SMELLS, REFACTORING CLEAN CODE, CODE SMELLS, REFACTORING AND RELATED PRINCIPLES Barbora Bühnová buhnova@fi.muni.cz LAB OF SOFTWARE ARCHITECTURES AND INFORMATION SYSTEMS FACULTY OF INFORMATICS MASARYK UNIVERSITY, BRNO Outline

More information

Implementing evolution: Refactoring

Implementing evolution: Refactoring 2IS55 Software Evolution Implementing evolution: Refactoring Alexander Serebrenik Sources / SET / W&I 5-6-2012 PAGE 1 Last week How to implement evolution Last week: evolution strategies and decision making

More information

INF5120 Modellbasert Systemutvikling. F10-2: Architectural Patterns, Design Patterns and Refactoring. Lecture Arne-Jørgen Berre

INF5120 Modellbasert Systemutvikling. F10-2: Architectural Patterns, Design Patterns and Refactoring. Lecture Arne-Jørgen Berre INF5120 Modellbasert Systemutvikling F10-2: Architectural Patterns, Design Patterns and Refactoring Lecture 28.03.2011 2011 Arne-Jørgen Berre Patterns: From Analysis to Implementation Analysis Design Implementation

More information

JAVA MOCK TEST JAVA MOCK TEST II

JAVA MOCK TEST JAVA MOCK TEST II http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your

More information

Refactoring with Eclipse

Refactoring with Eclipse Refactoring with Eclipse Seng 371 Lab 8 By Bassam Sayed Based on IBM article Explore refactoring functions in Eclipse JDT by Prashant Deva Code Refactoring Code refactoring is a disciplined way to restructure

More information

INF5120 Modellbasert Systemutvikling

INF5120 Modellbasert Systemutvikling INF5120 Modellbasert Systemutvikling F07-2: Architectural Patterns, Design Patterns and Refactoring Lecture 27.02.2017 Arne-Jørgen Berre Patterns: From Analysis to Implementation Analysis Design Implementation

More information

SOFTWARE ENGINEERING SOFTWARE EVOLUTION. Saulius Ragaišis.

SOFTWARE ENGINEERING SOFTWARE EVOLUTION. Saulius Ragaišis. SOFTWARE ENGINEERING SOFTWARE EVOLUTION Saulius Ragaišis saulius.ragaisis@mif.vu.lt CSC2008 SE Software Evolution Learning Objectives: Identify the principal issues associated with software evolution and

More information

Software Engineering I (02161)

Software Engineering I (02161) Software Engineering I (02161) Week 9 Assoc. Prof. Hubert Baumeister DTU Compute Technical University of Denmark Spring 2015 Last Week Software Development Process Version Control Contents Project planning

More information

Automating Big Refactorings for Componentization and the Move to SOA

Automating Big Refactorings for Componentization and the Move to SOA Automating Big Refactorings for Componentization and the Move to SOA IBM Programming Languages and Development Environments Seminar 2008 Aharon Abadi, Ran Ettinger and Yishai Feldman Software Asset Management

More information

Object-Oriented Design

Object-Oriented Design Object-Oriented Design Lecture 14: Design Workflow Department of Computer Engineering Sharif University of Technology 1 UP iterations and workflow Workflows Requirements Analysis Phases Inception Elaboration

More information

Code Smells & Refactoring

Code Smells & Refactoring Material and some slide content from: - Mehdi Amoui Kalareh - Fowler Refactoring book Code Smells & Refactoring Reid Holmes Lecture 18 - Tuesday November 22 2011. Program restructuring Software systems

More information

Object-Oriented Software Engineering Practical Software Development using UML and Java

Object-Oriented Software Engineering Practical Software Development using UML and Java Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes Lecture 5 5.1 What is UML? The Unified Modelling Language is a standard graphical

More information

כללי Extreme Programming

כללי Extreme Programming פיתוח מער כות תוכנה מבוססות Java כללי Extreme Programming אוהד ברזילי ohadbr@tau.ac.il Based on: K. Beck: Extreme Programming Explained. E. M. Burke and B.M. Coyner: Java Extreme Programming Cookbook.

More information

Logistics. Final Exam on Friday at 3pm in CHEM 102

Logistics. Final Exam on Friday at 3pm in CHEM 102 Java Review Logistics Final Exam on Friday at 3pm in CHEM 102 What is a class? A class is primarily a description of objects, or instances, of that class A class contains one or more constructors to create

More information

Refactoring. Herez Moise Kattan NUSP: João S. Brito Júnior NUSP:

Refactoring. Herez Moise Kattan NUSP: João S. Brito Júnior NUSP: Refactoring Herez Moise Kattan NUSP: 9860455 João S. Brito Júnior NUSP: 5889672 1 Definition Refactoring is the process of changing a software system in such a way that it does not* alter the external

More information

Recap: Class Diagrams

Recap: Class Diagrams Com S 362: Object-Oriented Analysis and Design Recap: Class Diagrams Class diagrams represent design structure Three parts: name, attribute, operations Visibility, attribute type, multiplicity Association,

More information

Test Driven Development and Refactoring. CSC 440/540: Software Engineering Slide #1

Test Driven Development and Refactoring. CSC 440/540: Software Engineering Slide #1 Test Driven Development and Refactoring CSC 440/540: Software Engineering Slide #1 Topics 1. Bugs 2. Software Testing 3. Test Driven Development 4. Refactoring 5. Automating Acceptance Tests CSC 440/540:

More information

EECS 4314 Advanced Software Engineering. Topic 10: Software Refactoring Zhen Ming (Jack) Jiang

EECS 4314 Advanced Software Engineering. Topic 10: Software Refactoring Zhen Ming (Jack) Jiang EECS 4314 Advanced Software Engineering Topic 10: Software Refactoring Zhen Ming (Jack) Jiang Acknowledgement Some slides are adapted from Professor Marty Stepp, Professor Oscar Nierstrasz Relevant Readings

More information

Reengineering II. Transforming the System

Reengineering II. Transforming the System Reengineering II Transforming the System Recap: Reverse Engineering We have a detailed impression of the current state We identified the important parts We identified reengineering opportunities We have

More information

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7

Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7 Computer Science 2 Lecture 4 Inheritance: Trinidad Fruit Stand 02/15/2014 Revision : 1.7 1 Problem Ralph owns the Trinidad Fruit Stand that sells its fruit on the street, and he wants to use a computer

More information

Course December Adrian Iftene

Course December Adrian Iftene Course 10 12 December 2016 Adrian Iftene adiftene@info.uaic.ro Recapitulation QoS Functional Testing Non-Functional Testing Rotting Design Refactoring 2 QoS = ability to provide different priority to different

More information

CSE 70 Final Exam Fall 2009

CSE 70 Final Exam Fall 2009 Signature cs70f Name Student ID CSE 70 Final Exam Fall 2009 Page 1 (10 points) Page 2 (16 points) Page 3 (22 points) Page 4 (13 points) Page 5 (15 points) Page 6 (20 points) Page 7 (9 points) Page 8 (15

More information

Object Fundamentals, Part One. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 2 08/27/2009

Object Fundamentals, Part One. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 2 08/27/2009 Object Fundamentals, Part One Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/5448 Lecture 2 08/27/2009 1 Lecture Goals Introduce basic concepts, terminology, and notations for object-oriented

More information

Hugbúnaðarverkefni 2 - Static Analysis

Hugbúnaðarverkefni 2 - Static Analysis Time to do some refactoring of my Java. Hugbúnaðarverkefni 2 - Static Analysis Fyrirlestrar 7 & 8 A Refactoring Micro-Example 15/01/2006 Dr Andy Brooks 1 Case Study Dæmisaga Reference A Refactoring Micro-Example,

More information

R E A D C L E A N C O D E : A H A N D B O O K O F S O F T W A R E C R A F T S M A N S H I P. C H A P T E R S 2 A N D 4.

R E A D C L E A N C O D E : A H A N D B O O K O F S O F T W A R E C R A F T S M A N S H I P. C H A P T E R S 2 A N D 4. R E A D C L E A N C O D E : A H A N D B O O K O F S O F T W A R E C R A F T S M A N S H I P. C H A P T E R S 2 A N D 4. H T T P S : / / R E F A C T O R I N G. G U R U / R E F A C T O R I N G / C A T A

More information

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 5: Modelling with Classes

Object-Oriented Software Engineering Practical Software Development using UML and Java. Chapter 5: Modelling with Classes Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 5: Modelling with Classes 5.1 What is UML? The Unified Modelling Language is a standard graphical language

More information

bright code, dull code by fox \

bright code, dull code by fox \ bright code, dull code by fox peterson @a_fox_box \ Can you think of a time you ve been here? You come across a piece of code, you are expected to be able to work with it, and you re thinking I DIDN T

More information

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module

Client Code - the code that uses the classes under discussion. Coupling - code in one module depends on code in another module Basic Class Design Goal of OOP: Reduce complexity of software development by keeping details, and especially changes to details, from spreading throughout the entire program. Actually, the same goal as

More information

A Study of Bad Smells in Code

A Study of Bad Smells in Code International Journal for Science and Emerging ISSN No. (Online):2250-3641 Technologies with Latest Trends 7(1): 16-20 (2013) ISSN No. (Print): 2277-8136 A Study of Bad Smells in Code Gurpreet Singh* and

More information

Software Reengineering Refactoring To Patterns. Martin Pinzger Delft University of Technology

Software Reengineering Refactoring To Patterns. Martin Pinzger Delft University of Technology Software Reengineering Refactoring To Patterns Martin Pinzger Delft University of Technology Outline Introduction Design Patterns Refactoring to Patterns Conclusions 2 The Reengineering Life-Cycle (1)

More information

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO

PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE. Speaking the Language of OO PRINCIPLES OF SOFTWARE BIM209DESIGN AND DEVELOPMENT 00. WELCOME TO OBJECTVILLE Speaking the Language of OO COURSE INFO Instructor : Alper Bilge TA : Gökhan Çıplak-Ahmet Alkılınç Time : Tuesdays 2-5pm Location

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1 What is a Design Pattern? Each pattern Describes a problem which occurs over and over again in our environment,and then describes the core of the problem Novelists, playwrights and other writers rarely

More information

More on Objects in JAVA TM

More on Objects in JAVA TM More on Objects in JAVA TM Inheritance : Definition: A subclass is a class that extends another class. A subclass inherits state and behavior from all of its ancestors. The term superclass refers to a

More information

CSC9T4: Object Modelling, principles of OO design and implementation

CSC9T4: Object Modelling, principles of OO design and implementation CSC9T4: Object Modelling, principles of OO design and implementation CSCU9T4 Spring 2016 1 Class diagram vs executing program The class diagram shows us a static view of the responsibilities and relationships

More information

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II

Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Advanced Programming - JAVA Lecture 4 OOP Concepts in JAVA PART II Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Ad hoc-polymorphism Outline Method overloading Sub-type Polymorphism Method overriding Dynamic

More information

CMSC 132: Object-Oriented Programming II

CMSC 132: Object-Oriented Programming II CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Polymorphism 1 / 19 Introduction to Object-Oriented Programming Today we ll learn how to combine all the elements of object-oriented programming in the design of a program that handles a company payroll.

More information

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology: Inheritance 1 Inheritance One class inherits from another if it describes a specialized subset of objects Terminology: the class that inherits is called a child class or subclass the class that is inherited

More information

1: Introduction to Object (1)

1: Introduction to Object (1) 1: Introduction to Object (1) 김동원 2003.01.20 Overview (1) The progress of abstraction Smalltalk Class & Object Interface The hidden implementation Reusing the implementation Inheritance: Reusing the interface

More information

CISC370: Inheritance

CISC370: Inheritance CISC370: Inheritance Sara Sprenkle 1 Questions? Review Assignment 0 due Submissions CPM Accounts Sara Sprenkle - CISC370 2 1 Quiz! Sara Sprenkle - CISC370 3 Inheritance Build new classes based on existing

More information

Specification and Automated Detection of Code Smells using OCL

Specification and Automated Detection of Code Smells using OCL Specification and Automated Detection of Code Smells using OCL Tae-Woong Kim 1, Tae-Gong Kim 2 and Jai-Hyun Seu 3 School of Computer Engineering, Inje University, Obang-dong 607, Gimhae, Gyeong-Nam, Korea

More information

Programming overview

Programming overview Programming overview Basic Java A Java program consists of: One or more classes A class contains one or more methods A method contains program statements Each class in a separate file MyClass defined in

More information

The GoF Design Patterns Reference

The GoF Design Patterns Reference The GoF Design Patterns Reference Version.0 / 0.0.07 / Printed.0.07 Copyright 0-07 wsdesign. All rights reserved. The GoF Design Patterns Reference ii Table of Contents Preface... viii I. Introduction....

More information

Chapter 15: A Longer Example

Chapter 15: A Longer Example Chapter 15: A Longer Example Reading individual refactorings is important, because you have to know the moves in order to play the game. Yet reading about refactorings one at a time can also miss the point,

More information

How We Refactor, and How We Know It

How We Refactor, and How We Know It Emerson Murphy-Hill, Chris Parnin, Andrew P. Black How We Refactor, and How We Know It Urs Fässler 30.03.2010 Urs Fässler () How We Refactor, and How We Know It 30.03.2010 1 / 14 Refactoring Definition

More information