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

Size: px
Start display at page:

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

Transcription

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

2 Introduc4on When considering soaware evolu4on, the key dis4nc4on is: Program's quality improves or degrades? Treat modifica4ons as opportuni4es to improve quality Monitor project quality regularly Warning if it degrades

3 Introduc4on A second dis4nc4on: Changes made during construc8on Changes made during maintenance Construc8on changes are usually made by the original developers Done under less pressure than maintenance changes Profit soaware changes to improve the code and its internal quality, so that future changes are easier

4 Introduc4on The key strategy in achieving soaware evolu8on is refactoring Fowler (1999): a change made to the internal structure of the soaware to make it easier to understand and cheaper to modify without changing its observable behaviour Reasons to Refactor Some4mes code degenerates under maintenance, and some4mes the code just wasn't very good in the first place

5 When Refactoring Warning signs that indicate where refactorings are needed: Code is duplicated A rou8ne is too long In object- oriented programming, rarely rou4nes longer than a screen A loop is too long or too deeply nested Loop innards tend to be good candidates for being converted into rou4nes A class has poor cohesion It takes ownership for a mix of unrelated responsibili4es A class interface does not provide a consistent level of abstrac8on A parameter list has too many parameters Changes require parallel modifica4ons to mul4ple classes

6 When Refactoring Refactoring warning signs (cont.): Related data items that are used together are not organized into classes A rou8ne uses more features of another class than of its own class A primi8ve data type is overloaded If using Integer for money, temperature, create separate classes for them A class doesn't do very much Move responsibili4es to other and remove it A chain of rou4nes just passes data along A middleman object isn't doing anything One class knows too much about another Stronger encapsula4on preferred to weaker

7 When Refactoring Refactoring warning signs (cont.): A rou4ne has a poor name Rename it wherever defined or used and recompile Data members are public Hide data behind ge^ers and se^ers A subclass uses only a small percentage of its parents' rou8nes Change rela4on to has- a Comments are used to explain difficult code Global variables are used A rou4ne uses setup code before a rou4ne call or takedown code a#er a rou4ne call Avoid crea4ng an object just to call it and aaer that unpack some of its fields A program contains code that seems like it might be needed someday

8 Specific Refactorings Data Main ones from Refactoring (Fowler 1999) h^p:// Data Refactorings: Replace a magic number with a named constant Replace literal like 3.14 with named constant like PI Rename a variable with a clearer or more informa8ve name The same applies to renaming constants, classes and rou4nes Move an expression inline Replace an intermediate variable that was assigned the result of an expression with the expression itself

9 Data Refactoring Inline Temps double baseprice = anorder.baseprice(); return (baseprice > 1000) return (anorder.baseprice() > 1000)

10 Specific Refactorings Data Data Refactorings (cont.): Replace an expression with a rou8ne Replace an expression with a rou4ne (usually so that the expression isn't duplicated in the code) Introduce an intermediate variable Assign an expression to an intermediate variable whose name summarizes the purpose of the expression Convert a mul8use variable to mul8ple single- use variables Create separate variables for each usage with a more specific name Use a local variable for local purposes rather than a parameter Convert a data primi8ve to a class If a data primi4ve needs addi4onal behaviour (e.g. Temperature)

11 Data Refactoring Split Temporary Variable double temp = 2 * (_height + _width); System.out.println (temp); temp = _height * _width; System.out.println (temp); final double perimeter = 2 * (_height + _width); System.out.println (perimeter); final double area = _height * _width; System.out.println (area);

12 Specific Refactorings Data Data refactorings (cont.): Convert a set of type codes to a class or an enumera8on Like: const int SCREEN = 0; const int PRINTER = 1; const int FILE = 2; Convert a set of type codes to a class with subclasses A base class for the type with subclasses for each type code Change an array to an object If different elements in the array are different types, create an object with fields Replace a tradi8onal record with a data class Centralize opera4ons concerning the record (error checking, persistence, )

13 Data Refactoring Replace Type Code with Subclasses

14 Specific Refactorings Statement- Level Statement- Level Refactorings: Decompose a boolean expression Simplify a boolean expression by introducing well- named intermediate variables Move a complex boolean expression into a well- named boolean func8on Improve readability and if used more than once, eliminate parallel modifica4ons Consolidate fragments that are duplicated within different parts of a condi8onal Move code repeated at the end of an else and if block to the end of the en4re if- then- else block Use break or return instead of a loop control variable

15 Data Refactoring Decompose Condi4onal 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);

16 Specific Refactorings Statement- Level Statement- Level Refactorings (cont.): Return as soon as you know the answer instead of assigning a return value within nested if- then- else statements Replace condi8onals (especially repeated case statements) with polymorphism Implement condi4onal logic into inheritance hierarchy and polymorphic rou4ne calls Create and use null objects instead of tes8ng for null values Consider moving the responsibility for handling null values out of the client code and into the class Example: referring to a resident whose name is not known as "occupant." Have the Customer class define the unknown resident as "occupant" instead of having Customer's client code repeatedly test for whether the customer's name is known and subs4tute "occupant" if not

17 Data Refactoring Decompose Condi4onal double getspeed() { switch (_type) { case EUROPEAN: return getbasespeed(); case AFRICAN: return getbasespeed() - getloadfactor(); case NORWEGIAN: return getbasespeed(_voltage); } throw new RuntimeException ("Should be unreachable"); }

18 Specific Refactorings Rou4ne- Level Rou4ne- Level Refactorings: Extract rou8ne/extract method Remove inline code from one rou4ne, and turn it into its own rou4ne Move a rou8ne's code inline Take code from a rou4ne whose body is simple and self- explanatory, and move that rou4ne's code inline where it is used Convert a long rou8ne to a class For a long rou4ne, turn it into a class and factor it into mul4ple rou4nes Add a parameter When rou4ne needs more informa4on from its caller, add a parameter Remove a parameter If a rou4ne no longer uses a parameter, remove it

19 Data Refactoring Extract Method void printowing() { printbanner(); //print details System.out.println ("name: " + _name); System.out.println ("amount" + getoutstanding()); } void printowing() { printbanner(); printdetails(getoutstanding()); } void printdetails (double outstanding) { System.out.println ("name: " + _name); System.out.println ("amount" + outstanding); }

20 Specific Refactorings Rou4ne- Level Rou4ne- Level Refactorings (cont.): Separate query opera8ons from modifica8on opera8ons If GetTotals() changes an object's state, separate the state- changing func4onality Combine similar rou8nes by parameterizing them Example: similar rou4nes differ only with respect to a constant value, combine them and pass the value as a parameter Separate rou8nes whose behaviour depends on parameters passed in Consider the reverse of the previous refactoring if the rou4ne is too complex Pass a whole object rather than specific fields Instead of passing several values from the same object Pass specific fields rather than a whole object If the object is created just to pass it to a rou4ne Encapsulate downcas8ng If a rou4ne returns an object, return the most specific type it knows about, specially for iterators, collec4ons,

21 Data Refactoring Encapsulate Downcast & Parameterise Method Object lastreading() { return readings.lastelement(); } Reading lastreading() { return (Reading) readings.lastelement(); }

22 Specific Refactorings Class Implementa4on Class Implementa4on Refactorings: Change value objects to reference objects Avoid crea4ng and maintaining numerous copies of large or complex objects, only one master copy (the value object) and the rest of the code uses references to that object (reference objects) Change reference objects to value objects Avoid excessive reference housekeeping for small or simple objects, make them value objects Replace virtual rou8nes with data ini8aliza8on Subclasses that vary according to constant values they return, avoid overriding member rou4nes in the derived classes, ini4alise them with appropriate constant values and keep base class generic code

23 Data Refactoring Change Value to Reference & Reference to Value

24 Specific Refactorings Class Implementa4on Class Implementa4on Refactorings (cont.): Change member rou8ne or data placement Consider general changes in an inheritance hierarchy to eliminate duplica4on in derived classes: Pull a rou4ne up into its superclass Pull a field up into its superclass Pull a constructor body up into its superclass Other changes made to support specializa4on in derived classes: Push a rou4ne down into its derived classes Push a field down into its derived classes Push a constructor body down into its derived classes Extract specialized code into a subclass Move class code used by only a subset of its instances into a subclass Combine similar code into a superclass Combine similar code from subclasses into the superclass

25 Data Refactoring Pull Up Constructor Body class Manager extends Employee... public Manager (String name, String id, int grade) { _name = name; _id = id; _grade = grade; } public Manager (String name, String id, int grade) { super (name, id); _grade = grade; }

26 Specific Refactorings Class Interface Class Interface Refactorings: Move a rou8ne to another class Convert one class to two If a class has two or more dis4nct areas of responsibility Hide a delegate Some4mes Class A calls Class B and C, when really it should call only Class B and B should call C Remove a middleman If Class A calls Class B and B calls Class C, have Class A call Class C directly Replace delega8on with inheritance If a class exposes every public rou4ne of a delegate class, inherit from the delegate class instead of just using the class Also possible to replace inheritance with delega4on, if inheritance effects not desired

27 Data Refactoring Replace Delega4on with Inheritance

28 Specific Refactorings Class Interface Class Interface Refactorings (cont.): Introduce a foreign rou8ne If a class needs an addi4onal rou4ne and you can't modify the class to provide it, you can create a new rou4ne within the client class that provides that func4onality. Introduce an extension class A unmodifiable class needs addi4onal rou4nes, create a new class subclassing the original class and adding new rou4nes or wrapping the class and exposing the new rou4nes Encapsulate an exposed member variable Make public data private and expose it through a rou4ne Remove Set() rou8nes for fields that cannot be changed Hide rou8nes that are not intended to be used outside the class Encapsulate unused rou8nes Rou4nely using only a por4on of a class's interface, create a new interface that exposes only those necessary rou4nes Collapse a superclass and subclass if their implementa8ons are very similar

29 Data Refactoring Introduce Foreign Method Date newstart = new Date (previousend.getyear(), previousend.getmonth(), previousend.getdate() + 1); Date newstart = nextday(previousend); private static Date nextday(date arg) { return new Date ( arg.getyear(), arg.getmonth(), arg.getdate() + 1); }

30 Specific Refactorings System- Level System- Level Refactorings Change unidirec8onal class associa8on to bidirec8onal class associa8on For two classes that need to use each other's features but only one knows about the other class, change them so that they both know about each other Change bidirec8onal class associa8on to unidirec8onal class associa8on For two classes that know about each other's features but only one really needs to know, change them so that one knows about the other but not vice versa. Provide a factory method rather than a simple constructor Use a factory method when need to create objects based on a type code or when want to work with reference objects rather than value objects Replace error codes with excep8ons or vice versa Depending on your error- handling strategy, make sure the code is using the standard approach

31 Data Refactoring Replace Constructor with Factory Method & Change Bidirec4onal Associa4on to Unidirec4onal Employee (int type) { _type = type; } static Employee create(int type) { return new Employee(type); }

32 Refactoring Safety If misused, can cause more harm than good A few simple guidelines to prevent missteps: Save the code you start with Keep refactorings small Small enough so easy to understand all the impacts of the changes Do refactorings one at a 8me Recompiling and retes4ng before the next one Make a list of steps you intend to take Keep a list of intended refactorings Those not needed immediately Make frequent checkpoints Save checkpoints at various steps in a refactoring session

33 Refactoring Safety Guidelines (cont.): Retest Reviews of changed code should be complemented by retests Add test cases Add new unit tests for the new code. Remove obsolete Review the changes Pair programming, formal / informal reviews,

34 Refactoring Strategies Guidelines for deciding priority refactorings: Refactor when you add a rou8ne Check if related rou4nes are well organized. If not, refactor them. Refactor when you add a class Opportunity to refactor classes closely related to the added class Refactor when you fix a defect From fixing a bug to improving other code prone to similar defects Target error- prone modules Modules that concentrate defects from tes4ng or review Target high- complexity modules Define an interface between clean code and ugly code, and then move code across the interface A common problem with legacy systems is poorly wri^en produc4on code, which must remain opera4onal at all 4mes

35 Key Points Program changes are a fact of life both during ini4al development and aaer ini4al release SoAware can either improve or degrade as it's changed. The Cardinal Rule of SoAware Evolu4on is that internal quality should improve with code evolu4on One key to success in refactoring is learning to pay a^en4on to the numerous warning signs or smells that indicate a need to refactor. Another key to refactoring success is learning numerous specific refactorings A final key to success is having a strategy for refactoring safely. Some refactoring approaches are be^er than others Refactoring during development is the best chance you'll get to improve your program, to make all the changes you'll wish you'd made the first 4me. Take advantage of these opportuni4es during development

36 Ac4vity Refactor the MiniProject source code following the strategies: Target module/s with higher concentra8on of defects during review and tes4ng Target high- complexity module/s For the selected modules, perform at least 10 refactorings The more diverse in kind and the more produc8ve towards soaware quality, the beyer Deliverables: Through Campus Virtual upload document describing all refactorings: class name, method name, line number, ini4al code, refactoring applied, result code, mo4va4on, Update resul4ng code at Github

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

void printowing(double amount) { printbanner(); printdetails(); void printdetails(double amount) { 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

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

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. 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

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

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

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. 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

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. 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

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

So#ware Engineering I. Based on materials by Ken Birman, Cornell

So#ware Engineering I. Based on materials by Ken Birman, Cornell So#ware Engineering I Based on materials by Ken Birman, Cornell 1 So#ware Engineering The art by which we start with a problem statement and gradually evolve a solu@on There are whole books on this topic

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

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

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

CISC327 - So*ware Quality Assurance

CISC327 - So*ware Quality Assurance CISC327 - So*ware Quality Assurance Lecture 23 Code Inspec

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

RDD and Strategy Pa.ern

RDD and Strategy Pa.ern RDD and Strategy Pa.ern CSCI 3132 Summer 2011 1 OO So1ware Design The tradi7onal view of objects is that they are data with methods. Smart Data. But, it is be.er to think of them as en##es that have responsibili#es.

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

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

Principles of So3ware Construc9on. A formal design process, part 2

Principles of So3ware Construc9on. A formal design process, part 2 Principles of So3ware Construc9on Design (sub- )systems A formal design process, part 2 Josh Bloch Charlie Garrod School of Computer Science 1 Administrivia Midterm exam Thursday Review session Wednesday,

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

Inheritance and delega9on

Inheritance and delega9on Principles of So3ware Construc9on: Objects, Design, and Concurrency Designing classes Inheritance and delega9on Josh Bloch Charlie Garrod School of Computer Science 1 Administrivia Homework 2 due tonight

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

Introduc)on to So,ware Technology So#ware Quality

Introduc)on to So,ware Technology So#ware Quality Introduc)on to So,ware Technology So#ware Quality Klaus Ostermann Some slides on refactoring adapted from CS246 course at U Waterloo 1 So,ware Quality How can we maintain or improve the quality of so,ware?

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

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

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

A formal design process, part 2

A formal design process, part 2 Principles of So3ware Construc9on: Objects, Design, and Concurrency Designing (sub-) systems A formal design process, part 2 Josh Bloch Charlie Garrod School of Computer Science 1 Administrivia Midterm

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

Object Oriented Design (OOD): The Concept

Object Oriented Design (OOD): The Concept Object Oriented Design (OOD): The Concept Objec,ves To explain how a so8ware design may be represented as a set of interac;ng objects that manage their own state and opera;ons 1 Topics covered Object Oriented

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

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

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

Version Control. So#ware Quality Quality Audit and Cer2fica2on. Master in Computer Engineering. Roberto García

Version Control. So#ware Quality Quality Audit and Cer2fica2on. Master in Computer Engineering. Roberto García Version Control So#ware Quality Quality Audit and Cer2fica2on Master in Computer Engineering Roberto García (rgarcia@diei.udl.cat) Introduc2on Change- control procedures. Avoid uncontrolled changes, destabilize

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

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

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

Encapsula)on, cont d. Polymorphism, Inheritance part 1. COMP 401, Spring 2015 Lecture 7 1/29/2015

Encapsula)on, cont d. Polymorphism, Inheritance part 1. COMP 401, Spring 2015 Lecture 7 1/29/2015 Encapsula)on, cont d. Polymorphism, Inheritance part 1 COMP 401, Spring 2015 Lecture 7 1/29/2015 Encapsula)on In Prac)ce Part 2: Separate Exposed Behavior Define an interface for all exposed behavior In

More information

Why OO programming? want but aren t. Ø What are its components?

Why OO programming? want but aren t. Ø What are its components? 9/21/15 Objec,ves Assign 1 Discussion Object- oriented programming in Java Java Conven,ons: Ø Constructors Ø Default constructors Ø Sta,c methods, variables Ø Inherited methods Ø Class names: begin with

More information

Garbage collec,on Parameter passing in Java. Sept 21, 2016 Sprenkle - CSCI Assignment 2 Review. public Assign2(int par) { onevar = par; }

Garbage collec,on Parameter passing in Java. Sept 21, 2016 Sprenkle - CSCI Assignment 2 Review. public Assign2(int par) { onevar = par; } Objec,ves Inheritance Ø Overriding methods Garbage collec,on Parameter passing in Java Sept 21, 2016 Sprenkle - CSCI209 1 Assignment 2 Review private int onevar; public Assign2(int par) { onevar = par;

More information

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance? CS6501 - Internet programming Unit- I Part - A 1 Define Java. Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look

More information

Josh Bloch Charlie Garrod Darya Melicher

Josh Bloch Charlie Garrod Darya Melicher Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 2: Class-level design Introduc9on to design paeerns Josh Bloch Charlie Garrod Darya Melicher 1 Administrivia Homework 1 feedback

More information

Josh Bloch Charlie Garrod Darya Melicher

Josh Bloch Charlie Garrod Darya Melicher Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 2: Class-level design Behavioral subtyping, design for reuse Josh Bloch Charlie Garrod Darya Melicher 1 Administrivia Homework 1

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

Array Basics: Outline

Array Basics: Outline Array Basics: Outline More Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and

More information

Generic programming POLYMORPHISM 10/25/13

Generic programming POLYMORPHISM 10/25/13 POLYMORPHISM Generic programming! Code reuse: an algorithm can be applicable to many objects! Goal is to avoid rewri:ng as much as possible! Example: int sqr(int i, int j) { return i*j; double sqr(double

More information

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004 Type Hierarchy Comp-303 : Programming Techniques Lecture 9 Alexandre Denault Computer Science McGill University Winter 2004 February 16, 2004 Lecture 9 Comp 303 : Programming Techniques Page 1 Last lecture...

More information

C++ (Non for C Programmer) (BT307) 40 Hours

C++ (Non for C Programmer) (BT307) 40 Hours C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular

More information

Design Pa*erns. + Anima/on Undo/Redo Graphics and Hints

Design Pa*erns. + Anima/on Undo/Redo Graphics and Hints Design Pa*erns + Anima/on Undo/Redo Graphics and Hints Design Pa*erns Design: the planning that lays the basis for the making of every object or system Pa*ern: a type of theme of recurring events or objects

More information

Designing with patterns - Refactoring. What is Refactoring?

Designing with patterns - Refactoring. What is Refactoring? Designing with patterns - Refactoring Bottom up based application of patterns Improving the design after it has been written What is Refactoring? Two definitions, the object and act of change in software

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

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

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

Genericity. Philippe Collet. Master 1 IFI Interna3onal h9p://dep3nfo.unice.fr/twiki/bin/view/minfo/sofeng1314. P.

Genericity. Philippe Collet. Master 1 IFI Interna3onal h9p://dep3nfo.unice.fr/twiki/bin/view/minfo/sofeng1314. P. Genericity Philippe Collet Master 1 IFI Interna3onal 2013-2014 h9p://dep3nfo.unice.fr/twiki/bin/view/minfo/sofeng1314 P. Collet 1 Agenda Introduc3on Principles of parameteriza3on Principles of genericity

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

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully

More information

Array Basics: Outline

Array Basics: Outline Array Basics: Outline More Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and

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

Chapter 6: Structural Design

Chapter 6: Structural Design Chapter 6: Structural Design Class Rela5onships Design alterna,ves for class use and reuse Composi5on Containment Inheritance Code Reuse Design Principles Rela5onships: Containment aka Holds- A subobjects

More information

Objec,ves. Review: Object-Oriented Programming. Object-oriented programming in Java. What is OO programming? Benefits?

Objec,ves. Review: Object-Oriented Programming. Object-oriented programming in Java. What is OO programming? Benefits? Objec,ves Object-oriented programming in Java Ø Encapsula,on Ø Access modifiers Ø Using others classes Ø Defining own classes Sept 16, 2016 Sprenkle - CSCI209 1 Review: Object-Oriented Programming What

More information

Overview of Eclipse Lectures. Module Road Map

Overview of Eclipse Lectures. Module Road Map Overview of Eclipse Lectures 1. Overview 2. Installing and Running 3. Building and Running Java Classes 4. Refactoring Lecture 2 5. Debugging 6. Testing with JUnit 7. Version Control with CVS 1 Module

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

CO Java SE 8: Fundamentals

CO Java SE 8: Fundamentals CO-83527 Java SE 8: Fundamentals Summary Duration 5 Days Audience Application Developer, Developer, Project Manager, Systems Administrator, Technical Administrator, Technical Consultant and Web Administrator

More information

Charlie Garrod Bogdan Vasilescu

Charlie Garrod Bogdan Vasilescu Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 1: Design for change (class level) Introduc9on to Java + Design for change: Informa9on hiding Charlie Garrod Bogdan Vasilescu School

More information

CSE Compilers. Reminders/ Announcements. Lecture 15: Seman9c Analysis, Part III Michael Ringenburg Winter 2013

CSE Compilers. Reminders/ Announcements. Lecture 15: Seman9c Analysis, Part III Michael Ringenburg Winter 2013 CSE 401 - Compilers Lecture 15: Seman9c Analysis, Part III Michael Ringenburg Winter 2013 Winter 2013 UW CSE 401 (Michael Ringenburg) Reminders/ Announcements Project Part 2 due Wednesday Midterm Friday

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

PROGRAMMING LANGUAGE 2

PROGRAMMING LANGUAGE 2 31/10/2013 Ebtsam Abd elhakam 1 PROGRAMMING LANGUAGE 2 Java lecture (7) Inheritance 31/10/2013 Ebtsam Abd elhakam 2 Inheritance Inheritance is one of the cornerstones of object-oriented programming. It

More information

Op>onal. The Mother of all Bikesheds. Stuart Marks Core Libraries Java PlaGorm Group, Oracle

Op>onal. The Mother of all Bikesheds. Stuart Marks Core Libraries Java PlaGorm Group, Oracle Op>onal The Mother of all Bikesheds Stuart Marks Core Libraries Java PlaGorm Group, Oracle Copyright 2016, Oracle and/or its affiliates. All rights reserved. Op>onal The Mother of all Bikesheds What is

More information

Charlie Garrod Michael Hilton

Charlie Garrod Michael Hilton Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 5: Concurrency Introduc9on to concurrency, part 2 Concurrency primi9ves, con9nued Charlie Garrod Michael Hilton School of Computer

More information

Josh Bloch Charlie Garrod Darya Melicher

Josh Bloch Charlie Garrod Darya Melicher Principles of So3ware Construc9on: Objects, Design, and Concurrency Part 42: Concurrency Introduc9on to concurrency Josh Bloch Charlie Garrod Darya Melicher 1 Administrivia Homework 5 team sign-up deadline

More information

Chair of Software Engineering Java and C# in Depth

Chair of Software Engineering Java and C# in Depth Chair of Software Engineering Java and C# in Depth Exercise Session Week 3 Agenda Ø Assignment I Review Ø Class Ini;aliza;on and Class Instance Crea;on Ø Quizzes Ø Assignment II Handout 2 Class Diagram

More information

COSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan

COSC 121: Computer Programming II. Dr. Bowen Hui University of Bri?sh Columbia Okanagan COSC 121: Computer Programming II Dr. Bowen Hui University of Bri?sh Columbia Okanagan 1 A1 Posted over the weekend Two ques?ons (s?ll long ques?ons) Review of main concepts from COSC 111 Prac?ce coding

More information

UNIT II A. ENTITY RELATIONSHIP MODEL

UNIT II A. ENTITY RELATIONSHIP MODEL UNIT II A. ENTITY RELATIONSHIP MODEL Agenda En0ty & En0ty Sets A6ributes Rela0onship & Rela0onship Sets Constraints Mapping Cardinali0es, Par0cipa0on Constraints, Keys E-R Diagrams & Design of Database

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 21 October 21 st, 2015 Transi@on to Java Announcements HW5: GUI & Paint Due Tomorrow, October 22 nd at 11:59pm HW6: Java Programming (Pennstagram)

More information

Agenda. Excep,ons Object oriented Python Library demo: xml rpc

Agenda. Excep,ons Object oriented Python Library demo: xml rpc Agenda Excep,ons Object oriented Python Library demo: xml rpc Resources h?p://docs.python.org/tutorial/errors.html h?p://docs.python.org/tutorial/classes.html h?p://docs.python.org/library/xmlrpclib.html

More information

Object Oriented Programming. Feb 2015

Object Oriented Programming. Feb 2015 Object Oriented Programming Feb 2015 Tradi7onally, a program has been seen as a recipe a set of instruc7ons that you follow from start to finish in order to complete a task. That approach is some7mes known

More information

Java. Package, Interface & Excep2on

Java. Package, Interface & Excep2on Java Package, Interface & Excep2on Package 2 Package Java package provides a mechanism for par55oning the class name space into more manageable chunks Both naming and visibility control mechanism Define

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

10.5 Polymorphism. def presentquestion(q) : q.display() response = input("your answer: ") print(q.checkanswer(response)) 11/11/16 39

10.5 Polymorphism. def presentquestion(q) : q.display() response = input(your answer: ) print(q.checkanswer(response)) 11/11/16 39 10.5 Polymorphism QuestionDemo2 passed two ChoiceQuestion objects to the presentquestion() method Can we write a presentquestion() method that displays both Question and ChoiceQuestion types? With inheritance,

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

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

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

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

CS-202 Introduction to Object Oriented Programming

CS-202 Introduction to Object Oriented Programming CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction

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

CISC327 - So*ware Quality Assurance

CISC327 - So*ware Quality Assurance CISC327 - So*ware Quality Assurance Lecture 8 Introduc

More information

Introduction. Object-Oriented Programming Spring 2015

Introduction. Object-Oriented Programming Spring 2015 Introduction Object-Oriented Programming 236703 Spring 2015 1 Course Staff Lecturer in charge: Prof. Eran Yahav Lecturer: Eran Gilad TA in charge: Nurit Moscovici TAs: Helal Assi, Eliran Weiss 3 Course

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

What? reorganising its internal structure

What? reorganising its internal structure What? Improving a computer program by reorganising its internal structure without t altering its external behaviour. (http://dictionary.reference.com/browse/refactoring ) Why? Improves the over all design

More information

Array Basics: Outline

Array Basics: Outline Array Basics: Outline More Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and

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

Inheritance and Interfaces

Inheritance and Interfaces Inheritance and Interfaces Object Orientated Programming in Java Benjamin Kenwright Outline Review What is Inheritance? Why we need Inheritance? Syntax, Formatting,.. What is an Interface? Today s Practical

More information

Condi(onals and Loops

Condi(onals and Loops Condi(onals and Loops 1 Review Primi(ve Data Types & Variables int, long float, double boolean char String Mathema(cal operators: + - * / % Comparison: < > = == 2 A Founda(on for Programming any program

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

Sept 26, 2016 Sprenkle - CSCI Documentation is a love letter that you write to your future self. Damian Conway

Sept 26, 2016 Sprenkle - CSCI Documentation is a love letter that you write to your future self. Damian Conway Objec,ves Javadocs Inheritance Ø Final methods, fields Abstract Classes Interfaces Sept 26, 2016 Sprenkle - CSCI209 1 JAVADOCS Documentation is a love letter that you write to your future self. Damian

More information

Chapter 5 Object-Oriented Programming

Chapter 5 Object-Oriented Programming Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares

More information

11/4/15. Review. Objec&ves. Refactoring for Readability. Review. Liskov Subs&tu&on Principle (LSP) LISKOV SUBSTITUTION PRINCIPLE

11/4/15. Review. Objec&ves. Refactoring for Readability. Review. Liskov Subs&tu&on Principle (LSP) LISKOV SUBSTITUTION PRINCIPLE Objec&ves Liskov Subs&tu&on Principle Good enough design Refactoring for Extensibility Review What are some metrics of code design? Ø How can we use the metric? Ø What is the intui&on behind the metric?

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