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

Size: px
Start display at page:

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

Transcription

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

2 What is Refactoring? Process of changing a software system in ways that does not affect the internal behaviour of the software, yet improves the internal structure A disciplined way to clean up code that minimizes the probability of introducing bugs Improving the design of the code after it is written Taking lots of small steps in order to accomplish these things

3 Why Refactor? Over time, even initially good code can become spaghetti code (the quality of design deteriorates over time). As a system grows, you learn more about how it ideally should be designed. The more you know, the more assumptions you can confirm, or reject, and thus make better choices. Keeping up with these choices requires old code to be changed. Without refactoring, automation can be very difficult to achieve!

4 Consolidate Conditionals Original Code: def determineeligableamount(): if (age > 65): return 0.0 if (isparttime): return 0.0 if (age < 18): return 0.0 #determine specific amount. return amount Refactored Code: def determineeligableamount(): if (age > 65) or (isparttime) or (age < 18): return 0.0 #determine specific amount. return amount Can anything further be done?

5 Extract Method Original Code: def determineeligableamount(): if (age > 65) or (isparttime) or (age < 18): return 0.0 #determine specific amount. return amount Refactored Code: def determineeligableamount(): if (isnoteligable()): return 0.0 #determine specific amount. return amount def isnoteligable(): return (age > 65) or (isparttime) or (age < 18) Although the refactored code is longer, it is easier to read, and the method created may be useful elsewhere!

6 Consolidate Duplicate Conditional Fragments Original Code: Refactored Code: if(isspecialprice) { total = price * 0.85; submitsale(total); else { total = price; submitsale(total); if(isspecialprice) { total = price * 0.85; else { total = price; submitsale(total); Look for code that is run in all conditional branches (including any else conditions. Pull this code out and place it below the conditional block. Be weary of false applicability of this however, if there is no else block for example!

7 Remove Control Flags (start break war) Original Code: Refactored Code: protected void validatesecurity (ArrayList<Person> people) { boolean found = false; for(person person : people) { if (!found) { if (person.equals("joe")) { //run actions for Joe //... found = true; if (person.equals("paco")) { //run actions for Paco //... found = true; //rest of program protected void validatesecurity(arraylist<person> people) { for(person person : people) { if (person.equals("joe")) { //run actions for Joe //... break; if (person.equals("paco")) { //run actions for Paco //... break; //rest of program

8 Replace Nested Conditionals Original Code: public int getresultantamount() { int result = 0; if (issingle) { result = singleamnt(); else { if (isseperated) { result = seperatedamnt(); else { if (ismarried) { result = marriedamnt(); return result; Refactored Code: public int getresultantamount() { if (issingle) { return singleamnt(); if (isseperated) { return seperatedamnt(); if (ismarried) { return marriedamnt(); return 0; Nested conditions are often the result of someone quickly entering new code in to solve for a very small specific problem without thinking about the larger design. Any time these are seen, it is a good idea to re-visit the logic, and see if there is a better way to format the conditionals, and land at the same result.

9 Replace Nested Conditions Original Code: def getadjustedcapital(): result = 0.0 if (_capital > 0.0): if (_intrestrate > 0.0) and (_duration > 0.0): result = (_income / _duration) * ADJ_FACTOR return result Refactored Code: def getadjustedcapital(): if (_capital > 0.0) and (_intrestrate > 0.0) and (_duration > 0.0): return (_income / _duration) * ADJ_FACTOR return 0.0 def getadjustedcapital(): if (_capital <= 0.0) or (_intrestrate <= 0.0) or (_duration <= 0.0): return 0.0 return (_income / _duration) * ADJ_FACTOR def getadjustedcapital(): if noadjustment(): return 0.0 return (_income / _duration) * ADJ_FACTOR def noadjustment(): return (_capital <= 0.0) or (_intrestrate <= 0.0) or (_duration <= 0.0)

10 Replace Magic Numbers with Constants Original Code: public double potentialenergy (double mass, double height) { return mass * 9.81 * height; Refactored Code: public static final double GRAVITY = 9.81; public double potentialenergy(double mass, double height) { return mass * GRAVITY * height; This should be fairly self-explanatory. By replacing with constants, code readability goes up significantly, and if something ever changes, it only needs to be changed in one position in the code.

11 Encapsulate Fields Original Code: public String name; Refactored Code: private String name; public String getname() { return name; public void setname(string name) { this.name = name; Note that a getter should always be made (even if it s protected), but setter is much more optional, depending on the purpose of the code

12 Encapsulate Collections Original Code: public class Student { public Set<Course> courses; Refactored Code: public class Student { private Set<Course> courses; public Set<Course> getcourses() { return courses; public void setcourses(set<course> courses) { this.courses = courses; This code, although better, still isn t fully encapsulating the collection. Why?

13 Encapsulate Collections - Continued Original Code: public class Student { private Set<Course> courses; public Set<Course> getcourses() { return courses; Refactored Code: public class Student { private Set<Course> courses; public Set<Course> getcourses() { return Collections.unmodifiableSet(courses); public void setcourses( Set<Course> courses) { this.courses = courses; public void initcourses(set<course> courses) { this.courses = new HashSet<Course>(); for (Course c : courses) { this.courses.add(c); public void addcourse(course c) { this.courses.add(c);

14 Parametrize Methods Original Code: class Employee { double salary; void fivepercentraise() { salary = salary * 1.05; Refactored Code: class Employee { double salary; void raise(int percent) { salary = salary * (1+(percent/100)); void tenpercentraise() { salary = salary * 1.10; void fivepercentraise() { raise(5); void tenpercentraise() { raise(10); Why were methods fivepercentraise and tenpercentraise left behind?

15 Replace Parameter with Explicit Method Original Code: def setvalue(name, vale): if (name == "width"): self.width = value if (name == "height"): self.height = value Refactored Code: def setwidth(vale): self.width = value def setheight(value): self.height = value def setvalue(name, vale): if (name == "width"): setwidth(value) if (name == "height"): setheight(value) Although the refactored code is longer, it is easier to read, and the method created may be useful elsewhere!

16 Introduce Explaining Variables Original Code: public double price() { //base price - volume discount + shipping return this.itemprice * quantity - Math.max(0, this.quantity - 500) * this.itemprice * Math.min(this.itemWeight * this.itemprice * 0.01, 100.0); Refactored Code: public double price() { final double baseprice = this.itemprice * quantity; final double volumediscount = Math.max(0, this.quantity - 500); final double shipping = Math.min(this.itemWeight * this.itemprice * 0.01, 100.0); return baseprice - volumediscount + shipping; This form of refactoring is purely about readability. The code created after refactoring is much easier to read for a future user. What other refactoring could be done on the refactored code?

17 More Interesting Refactoring These previous examples have all been fairly simple ways to refactor code, which are primarily based upon a mix of readability and efficiency of code. They are all based on specific methods or fields within an existing class. Next, we are going to dig into some more complex forms of refactoring. These will primarily focus on the design of the software, and will impact classes more than methods.

18 Extract Superclass Starting off with two classes that seem to be highly related, we want to determine if there is a way to build a logical superclass, which contains some of the common functionality and fields from the two distinct classes.

19 Extract Subclass Sometimes we will want to move in the opposite direction, and extract a subclass. When you start seeing large if blocks checking if flags are set on a class, usually this is a good time to see if the flagged items are unique enough to merit a new subclass be created.

20 Pull up method / field Sometimes, subclasses will all contain a similar method that in the majority of cases acts the same way. We want to reduce the amount of duplicate code, so these code pieces should be pulled up higher

21 Push Down Methods / fields Sometimes our super classes have fields not being used by all the subclasses. In these cases, we want to push the methods down.

22 Replace Inheritance with Delegations Sometimes, inheritance is not the best solution, and we are better to use delegations. Notice that the arrow has changed from a filled arrowhead to an open arrowhead. This means that the Stack will contain a vector that it will use.

23 Replace Inheritance with Delegation class Stack<E> { private Vector<E> vector; public Stack() { vector = new Vector<>(); public void push(e e) { vector.insertelementat(e, 0); public E pop() { E e = vector.elementat(0); vector.removeelementat(0); return e; public int size() { return vector.size(); public boolean isempty() { return vector.isempty();

24 Replace Delegation with Inheritance Sometimes, delegation is not the best strategy. While initially designing we may have decided to use the Object Adapter, based on the specific circumstance presented. Later, it might become apparent that a class Adapter was a much better choice When can we not do this?

25 Replace a Method with a Method Object public class Account { // don't try to figure out what this does public int gamma ( int inputval, int quantity, int yeartodate ) { int importantvalue1 = (inputval * quantity) + delta(); int importantvalue2 = (inputval * yeartodate) + 100; if.. // a very long and complicated computation // that makes heavy use of importantvalues return importantvalue3 factor() * importantvalue1;

26 Replace a Method with a Method Object public class Gamma { private final Account account; private int inputvalue;... private int importantvalue1; Gamma(Account account, int inval, int q, int ytd) { this.account = acc;... public class Account { // don't try to figure out what this does public int gamma ( int inputval, int quantity, int yeartodate ) { int importantvalue1 = (inputval * quantity) + delta(); int importantvalue2 = (inputval * yeartodate) + 100; if.. // a very long and complicated computation // that makes heavy use of importantvalues return importantvalue3 factor() * importantvalue1;

27 Replace a Method with a Method Object public class Gamma {... public int compute () { importantvalue1 = (inputval * quantity) + this.account.delta(); importantvalue = (inputval * yeartodate) + 100;. // and so on public class Account { public int gamma ( int inputval, int quantity, int yeartodate ) { return (new Gamma(this, inputval, quantity, yeartodate)).compute();

28 Replace Condition with Polymorphism private enum EmployeeType {ENGINEER, SALESMAN, MANAGER public double payamount() { switch (type) { case ENGINEER: return monthlysalary; case SALESMAN: return monthlysalary + commission; case MANAGER: return monthlysalary + bonus; default: throw new RuntimeException("Incorrect Employee");

29 Replace Condition with Polymorphism public class Employee { private EmployeeType type; double payamount() { return type.payamount(); public abstract class EmployeeType { public abstract double payamount(); public double payamount() { return monthlysalary; public double payamount() { return monthlysalary + commission; public double payamount() { return monthlysalary + bonus; In Engineer In SalesPerson In Manager

30 Replace Condition with Polymorphism What design pattern was this refactoring switching to?

31 Introduce null Object Sometimes we are required to make a very large number of null checks throughout our code in languages like Java where we can never be sure if a return is an object or a null. Customer customer if ( customer == null ) { plan = BillingPlan.basic(); else { plan = _customer.getplan(); if ( customer!= null ) { customer.setname(n); if ( customer!= null ) { points = _customer.getpoints(); else { points = 0;... Customer customer plan = customer.getplan(); customer.setname(n); points = customer.getpoints(); class NullCustomer extends Customer { public BillingPlan getplan() { return BillingPlan.basic(); public int getpoints() { return 0; public void setname(string n) {

32 Introduce Local Extension Sometimes there are classes that we want to add to, but we are unable to modify (such as a server side class).

33 Tease Apart Inheritance Sometimes we will find after inspecting our structure that there seems to be two jobs being done at once by all classes in a hierarchy

34 How to decide when to refactor It is always to your benefit to refactor if you have the time to do it. The challenge is, how do you find the easy to refactor pieces of code quickly? One way to determine this is using code smells. These are common issues that appear within code and begin to smell off. When we see (or smell) these issues, we want to take the appropriate actions, and refactor our code appropriately

35 Code Smells We have all come across code that just doesn t seem right when we look at it. Code smells are an attempt to cleanly classify what is causing us to say something is wrong, and give us options on how to quickly fix it. These smells are usually things you get better at identifying over time, but it is good to think about them early in your careers, and begin to take notice of them in code you are reviewing.

36 Code Smells (In reality, no one is going to be this mean to you! It is always good to understand what kind of things other developers are going to be looking for in your code, and what to look for in their code so that we can all make better software!)

37 Code Smells Bad smelling code can stink in one of two areas: 1. Within a specific class / method 2. Between classes (sometimes called design smells) There is no one exhaustive list of all the possible smells that may be detected in code, but there are many good lists out there. We will review several of the more common smells, and what to do about them, but I would also suggest reading more on your own time about these smells. A good starting place is What s a better name for Code Smells? COdours

38 Code Smell Taxonomy Bloaters Object Oriented Abusers Change Preventers Dispensables Couplers Long Method Large Class Primitive Obsession Long Parameter List Data Clumps Switch Statements Temporary Field Refused Bequest Alternative Classes with Different Interfaces Divergent Change Shotgun Surgery Parallel Inheritance Hierarchies Lazy class Data class Duplicate Code Dead Code Speculative Generality Comments! Feature Envy Inappropriate Intimacy Message Chains Middle Man

39 Bloaters What are they? Bloaters are smells representative of something that has grown too big. They can be too big themselves (Such as long methods) or something that inherently is seen when bloating is occuring (such as primitive obsession).

40 Long Methods The Smell: Long methods that have endless (exaggeration) amounts of code Why it s bad: When methods get very long, we immediately lose the ability to do two key things. The code becomes hard to expand further as the logic is hard to see, and the code becomes hard to read in general, requiring more time to be spent on it, when a necessary update occurs. The Solution: There are many solutions to this specific smell, depending on what has caused the method to grow. The first step is usually to see if there are any methods that can be extracted. There may be cases for introducing new parameters, or to simply build a method object

41 Large Classes The Smell: Seeing classes that are on the large slide, perhaps they have many parameters to their constructors, or they have a massive number of available methods Why it s bad: Large classes often have too many responsibilities, resulting in them having to be modified any time a new requirement is determined. Further to this, since they are large, each of these changes usually has a cascading effect throughout the code base The Solution: Extract a new class or classes to do some of the work. Extract subclasses or a new class hierarchy, extract interfaces to begin segregating different methods.

42 Primitive Obsession The Smell: You only see primitives or near primitives (strings, Arrays) anywhere you look in the code. Why it s bad: Again, we are using objects for a reason! Objects let us deal with pieces of code in a logical way for the given problem at hand. Primitives are great if you are doing something primitive. If you are doing something more advance, build a class to help! The Solution: Replace data values with objects. Encapsulate commonly seen together primitives in their own class, and begin to replace these uses with this class. Likely you will find certain operations continually being made on these primitives. These methods can later become class methods for the new class.

43 Long Parameter List The Smell: Seeing a very large list of parameters going into a method. Why it s bad: In procedural programming, this may make sense, but in Object Oriented Programming it likely makes more sense to pull together the data we need in cases like this into it s own object, and access as required by the method. This is a smell that suggests this method is going to be highly volatile. The Solution: Replace the parameters with an object, replace the whole method with an object, replace some parameters with a pre-calculation method*

44 Data Clumps The Smell: Do you always see the same couple pieces of data together in the code? Like any time there is a String name, there is also an int age? Then likely these data points belong together. Why it s bad: Likely we can make this code easier to follow and more efficient by replacing these clumps of data. The Solution: Bring together these data pieces into logical objects.

45 Object Oriented Abusers What are they? Object oriented abusers are any smells that come off of code that does not take full advantage of object orientation. If we are going to be object oriented in our code, we need to be diligent about it!

46 Switch Statements The Smell: Seeing the same switch statements elsewhere in the code. Why it s bad: This is really showing a lack of well built object orientation. Take advantage of polymorphism! (What pattern can you use here?) The Solution(s): Fowler Options: Introduce null object Replace type code with State/Strategy Kerievsky Options: Replace conditional dispatch with command Move accumulation to visitor Not that switch!

47 Temporary Fields The Smell: You will likely come across code at some point that has a field named tmp/temp/x/z/blah/asd that sometimes is used, and other times is not. This is a bad smell Why it s bad: This creates difficult to use code, and is often the result of someone attempting to fix another problem (usually Long Parameter List) unsuccessfully. The Solution: Depending on the situation either extract a class or method to assist in this specialized functionality, or perhaps create a null object if this field is being used for null cases. Sometimes, the correct solution is simply renaming the field to something more relevant!

48 Refused Bequest What do a dog and a table have in common? Should a dog inherit from a table? The Smell: Sometimes, contrary to what should be done, people make poor inheritance choices. Why it s bad: This creates lots of confusing and often dead methods (table s bark method returns null) The Solution: Replace inheritance with delegation if there is a need for something from one object!

49 Alternative Classes with Different Interfaces The Smell: Two classes that behave the same on the inside, but look very different on the outside. Why it s bad: Often the commonality of the two classes can be pulled into a new class that is not requiring duplicate code. This is often a symptom of many small teams working on one large code base. Each requiring it s own way of doing very similar things The Solution: Based on above, the most common clean solution is to replace a full class with an adapter class, altering the interface just enough for what is required.

50 Change Preventers What are they? Change preventers are smells that are going to make it difficult to complete future changes. They are smells belonging to pieces of code that will likely prevent us from easily meeting our next mile stone. These types of smells are often signs of poor architectural choices being made.

51 Divergent Change The Smell: The given class is being changed a lot, for a lot of different reasons Why it s bad: This implies that the class must be doing many different things, and thus does not only have a single responsibility The Solution: The only real solution here is to look at what can be extracted into a new class or new classes

52 Shotgun Surgery The Smell: Making a change to one class causes cascading changes throughout the entire code base, regardless of the size of the initial change Why it s bad: This means you have high coupling throughout your code! The Solution: You will need to move around fields, and methods to try and make things less interdependent. Try looking for ways to create consolidated interfaces for the code

53 Parallel Inheritance Hierarchies The Smell: Any time Object family A grows by a class, object family B also grows by a class Why it s bad: This is really a special case of shotgun surgery (at the architecture level). You are going to likely need to modify hierarchies. The Solution: Look at ways of decoupling the two interdependent hierarchies. Can anyone think of a case where this was actually suggested by course material? What gives?

54 Dispensables What are they? Dispensables are the saddest of smells. They are not really needed. They are the useless, leftover, pointless items that for some reason, somebody included. They usually cause us to spend a great deal more time pondering their existence than we ought to have. They really would be better just not there. Why am I even here?

55 Lazy Class (Freeloader) The Smell: There is a class that whenever it is called upon, it passes its responsibility off to some other class or classes. It really isn t pulling its weight. Why it s bad: If something isn t doing enough, it should be taken out for both efficiency and readability of the code The Solution: Collapse the hierarchy, move responsibilities to their rightful owners

56 Data Class The Smell: Classes that only contain Fields, setters, and getters. Why it s bad: These classes, similar to lazy classes, are likely passing their responsibilities off to others to complete. These often appear as a result of someone attempting to fix primitive obsession. The Solution: Move methods into these classes, make them valuable!

57 Duplicate Code The Smell: The number one most common smell. This is seen more than any other smell. This is also known as copy paste code. This is referring to explicitly copied code. There can also be a lesser smell of subtly different copies code. Why it s bad: What happens when you need to modify that segment of logic? How do you know where all the copied code is? The Solution: If you hit ctrl+c, then move elsewhere in a file, and press ctrl+v question your choice. Prevention is the best cure! If you can t prevent (because it wasn t your mistake!) then look at factoring out a method to replace this repeated code. There are many other solutions, depending on the specific violation.

58 Dead Code The Smell: This is code that is never being used. Not rarely, but never. Code that either used to have a purpose, but no longer does, or code that may be used in the future (more on this later). Why it s bad: Dead code is useless, and can potentially introduce extra complexities to the logic of our programs that are unnecessary. The Solution: Delete it. (Use version control of course).

59 Speculative Generality The Smell: Futureproofing the code. Coding for what we think will happen. You will see code that is not used, and was never asked for by business. Often hidden below an if(false) statement or something similar to block its usage. Why it s bad: We can t predict the future, often times this is just wasted space and time. Sometimes, it can be even worse and make people believe a feature is there, that is not actually available. The Solution: Delete it! Version control will keep it if it was actually needed. The users would love that feature! Make it for when they ask! They will ask!

60 Comments The Smell: Comments inline comments especially. Why it s bad: Good code documents itself The Solution: Read the code associated with the comments, try and rename fields and variables to make it more comprehensible, so that the comments can be removed.

61 Couplers What are they? These smells represent a high level of coupling. As we ve talked about earlier this semester, coupling is bad. We want to strive to remove as much tight coupling as possible within our code base. These smells are good for identifying where coupling is occurring. By finding where, you can fix the problem. This is what leads to emergent architecture! Finding areas that ended up being more coupled than expected initially often suggest a change is needed to the system design.

62 Feature Envy The Smell: When a class is always calling on another class to help it in preparing it s data and getting it s variables in order, likely you have feature envy. Why it s bad: This is creating strong coupling between classes that may be entirely unnecessary The Solution: When a method is called more by another class than the class it is in, likely that method belongs in the other class, move it!

63 Inappropriate Intimacy The Smell: Do you see two classes together all the time? If class A is there, class B is surely to be called along soon? Or perhaps, they communicate in ways that are not appropriate (such as avoiding an interface and directly interacting) Why it s bad: This type of tight coupling often implies there is more going on with these classes than there should be. It can cause delays, or even expose information in ways we do not wish it to be. The Solution: Replace inheritance with delegation, move methods or fields around, change a currently bidirectional relationship with a unidirectional association. Attempt to reduce the coupling!

64 Message Chains The Smell: When you see a very long, consistent chain of fields or method calls being made in a row any time a piece of information is needed Why it s bad: This makes your code highly dependent on everything within this chain. These different objects have a high probability of being unrelated, and thus, might all have changes on different schedules. The Solution: Try and adjust where methods are, either by moving them up or down the chain, or perhaps, create a new interface (adapter) to help in the preparation.

65 Middle Men The Smell: If a class is delegating all of its work between other classes, or is working simply as a tunnel between two classes, what is its purpose? Why it s bad: These delegations are dependencies in disguise! We want to avoid creating large numbers of unnecessary calls. The Solution: Replace delegation with inheritance often will help in these cases. If not, kill the middle man. Middle man could also potentially be classified as a disposable.

66 Code Smells What s important to know It s important to understand that each given code smell comes with a list of common refactoring practices that can fix it. Knowing how to identify when refactoring is needed will help you in your career, as well as on being a better developer.

67 Questions?

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

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

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

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

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

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

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

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

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

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

Code Smells & Refactoring

Code Smells & Refactoring Material and some slide content from: - Mehdi Amoui Kalareh SERVICES COMPONENTS OBJECTS MODULES Code Smells & Refactoring Reid Holmes Lecture 21 - Thursday November 25 2010. Program restructuring Software

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

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

Clean

Clean Clean Code @mariosangiorgio Why? Goals Readable, maintainable and extendable code Meaningful names A simple example public List getthem() { List list1 = new ArrayList(); for (int[]

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

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

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

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

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

Maintainability and Agile development. Author: Mika Mäntylä

Maintainability and Agile development. Author: Mika Mäntylä Maintainability and Agile development Author: Mika Mäntylä ISO 9126 Software Quality Characteristics Are the required functions available in the software? How easy is it to

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

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

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

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

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

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

Exploring Software Refactoring Decisions in a Lean Startup

Exploring Software Refactoring Decisions in a Lean Startup Ömer Furkan Tercan Exploring Software Refactoring Decisions in a Lean Startup School of Science Thesis submitted for examination for the degree of Master of Science in Technology. Espoo 30.11.2015 Thesis

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

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

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

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

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich

CSCD01 Engineering Large Software Systems. Design Patterns. Joe Bettridge. Winter With thanks to Anya Tafliovich CSCD01 Engineering Large Software Systems Design Patterns Joe Bettridge Winter 2018 With thanks to Anya Tafliovich Design Patterns Design patterns take the problems consistently found in software, and

More information

OOP Design Conclusions and Variations

OOP Design Conclusions and Variations CS108, Stanford Handout #20 Fall, 2008-09 Osvaldo Jiménez OOP Design Conclusions and Variations Thanks to Nick Parlante for much of this handout Part 1 -- Mainstream OOP Design First, we have the standard,

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

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

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

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

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

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

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information

11/2/09. Code Critique. What goal are we designing to? What is the typical fix for code smells? Refactoring Liskov Substitution Principle

11/2/09. Code Critique. What goal are we designing to? What is the typical fix for code smells? Refactoring Liskov Substitution Principle Code Critique Identifying smells Refactoring Liskov Substitution Principle What goal are we designing to? What is the typical fix for code smells? What is a limitation of those fixes? How do we address

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

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

B. What strategy (order of refactorings) would you use to improve the code?

B. What strategy (order of refactorings) would you use to improve the code? { return title.gettext(); public boolean needssplit() { return costlabel.gettext().equals(" >3 "); public boolean needsestimate() { return costlabel.gettext().equals("? "); Challenges PG-1. Smells. A.

More information

Software LEIC. Lecture 23

Software LEIC. Lecture 23 Software Engineering @ LEIC Lecture 23 Last Lecture Software Architecture Architectural Patterns Application Architectures Software Architecture in the ES+SD Project Today Software Architecture Dependable

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

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

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change Chapter01.fm Page 1 Monday, August 23, 2004 1:52 PM Part I The Mechanics of Change The Mechanics of Change Chapter01.fm Page 2 Monday, August 23, 2004 1:52 PM Chapter01.fm Page 3 Monday, August 23, 2004

More information

Basic Object-Oriented Concepts. 5-Oct-17

Basic Object-Oriented Concepts. 5-Oct-17 Basic Object-Oriented Concepts 5-Oct-17 Concept: An object has behaviors In old style programming, you had: data, which was completely passive functions, which could manipulate any data An object contains

More information

Does Your Code Measure Up?

Does Your Code Measure Up? Does Your Code Measure Up? By: Adam Culp Twitter: @adamculp https://joind.in/13300 2 About me PHP 5.3 Certified Consultant at Zend Technologies Organizer SoFloPHP (South Florida) Organized SunshinePHP

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

Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018

Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 21: The Many Hats of Scala: OOP 10:00 AM, Mar 14, 2018 Contents 1 Mutation in the Doghouse 1 1.1 Aside: Access Modifiers..................................

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

For this chapter, switch languages in DrRacket to Advanced Student Language.

For this chapter, switch languages in DrRacket to Advanced Student Language. Chapter 30 Mutation For this chapter, switch languages in DrRacket to Advanced Student Language. 30.1 Remembering changes Suppose you wanted to keep track of a grocery shopping list. You could easily define

More information

Programming Style and Optimisations - An Overview

Programming Style and Optimisations - An Overview Programming Style and Optimisations - An Overview Summary In this lesson we introduce some of the style and optimization features you may find useful to understand as a C++ Programmer. Note however this

More information

Unit 5: More on Classes/Objects Notes

Unit 5: More on Classes/Objects Notes Unit 5: More on Classes/Objects Notes AP CS A The Difference between Primitive and Object/Reference Data Types First, remember the definition of a variable. A variable is a. So, an obvious question is:

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays

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

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

Reverse Engineering and Refactoring Related Concept in Software Engineering

Reverse Engineering and Refactoring Related Concept in Software Engineering Reverse Engineering and Refactoring Related Concept in Software Engineering Ajit kumar and Navin kumar. Research scholars. B. R. Ambedkar Bihar University. Muzaffarpur, Bihar (India). Guide:-Dr.D.L.Das.

More information

UNDERSTANDING CLASS DEFINITIONS CITS1001

UNDERSTANDING CLASS DEFINITIONS CITS1001 UNDERSTANDING CLASS DEFINITIONS CITS1001 Main concepts to be covered Fields / Attributes Constructors Methods Parameters Source ppts: Objects First with Java - A Practical Introduction using BlueJ, David

More information

Be careful when deciding whether to represent data as integers or floats, and be sure that you consider all possible behaviors in computation.

Be careful when deciding whether to represent data as integers or floats, and be sure that you consider all possible behaviors in computation. Table of Contents: 1. Integers and floats 2. for vs. while loops 3. Checking boolean conditions with if/else 4. Docstrings 5. Changing collections while iterating over them 6. Directly Accessing Instance

More information

QUIZ Friends class Y;

QUIZ Friends class Y; QUIZ Friends class Y; Is a forward declaration neeed here? QUIZ Friends QUIZ Friends - CONCLUSION Forward (a.k.a. incomplete) declarations are needed only when we declare member functions as friends. They

More information

A few important patterns and their connections

A few important patterns and their connections A few important patterns and their connections Perdita Stevens School of Informatics University of Edinburgh Plan Singleton Factory method Facade and how they are connected. You should understand how to

More information

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade

Plan. A few important patterns and their connections. Singleton. Singleton: class diagram. Singleton Factory method Facade Plan A few important patterns and their connections Perdita Stevens School of Informatics University of Edinburgh Singleton Factory method Facade and how they are connected. You should understand how to

More information

Using GitHub to Share with SparkFun a

Using GitHub to Share with SparkFun a Using GitHub to Share with SparkFun a learn.sparkfun.com tutorial Available online at: http://sfe.io/t52 Contents Introduction Gitting Started Forking a Repository Committing, Pushing and Pulling Syncing

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

Agile Architecture. The Why, the What and the How

Agile Architecture. The Why, the What and the How Agile Architecture The Why, the What and the How Copyright Net Objectives, Inc. All Rights Reserved 2 Product Portfolio Management Product Management Lean for Executives SAFe for Executives Scaled Agile

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

Super-Classes and sub-classes

Super-Classes and sub-classes Super-Classes and sub-classes Subclasses. Overriding Methods Subclass Constructors Inheritance Hierarchies Polymorphism Casting 1 Subclasses: Often you want to write a class that is a special case of an

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

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

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

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Table of Contents Introduction!... 1 Part 1: Entering Data!... 2 1.a: Typing!... 2 1.b: Editing

More information

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides

1B1b Inheritance. Inheritance. Agenda. Subclass and Superclass. Superclass. Generalisation & Specialisation. Shapes and Squares. 1B1b Lecture Slides 1B1b Inheritance Agenda Introduction to inheritance. How Java supports inheritance. Inheritance is a key feature of object-oriented oriented programming. 1 2 Inheritance Models the kind-of or specialisation-of

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

How To Make 3-50 Times The Profits From Your Traffic

How To Make 3-50 Times The Profits From Your Traffic 1 How To Make 3-50 Times The Profits From Your Traffic by Chris Munch of Munchweb.com Copyright Munchweb.com. All Right Reserved. This work cannot be copied, re-published, or re-distributed. No re-sell

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

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

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

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

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

These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

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

INTERFACES IN JAVA. Prof. Chris Jermaine

INTERFACES IN JAVA. Prof. Chris Jermaine INTERFACES IN JAVA Prof. Chris Jermaine cmj4@cs.rice.edu 1 Before We Begin... Couple more slides on checkers, then a challenge There is also an AIntelligence This encapsulates the idea of a checker-playing

More information

administrivia today UML start design patterns Tuesday, September 28, 2010

administrivia today UML start design patterns Tuesday, September 28, 2010 administrivia Assignment 2? promise to get past assignment 1 back soon exam on monday review slides are posted your responsibility to review covers through last week today UML start design patterns 1 Unified

More information

+ Abstract Data Types

+ Abstract Data Types Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract

More information

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?

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

Lab Exercise Refactoring using Eclipse

Lab Exercise Refactoring using Eclipse Lunds tekniska högskola Datavetenskap, Nov, 2017 Torbjörn Ekman and Görel Hedin (Modified from cvs to git by Ulf Asklund) EDAF45 Programvaruutveckling i grupp projekt Lab Exercise Refactoring using Eclipse

More information

Structure of Programming Languages Lecture 10

Structure of Programming Languages Lecture 10 Structure of Programming Languages Lecture 10 CS 6636 4536 Spring 2017 CS 6636 4536 Lecture 10: Classes... 1/23 Spring 2017 1 / 23 Outline 1 1. Types Type Coercion and Conversion Type Classes, Generics,

More information

Working with Objects. Overview. This chapter covers. ! Overview! Properties and Fields! Initialization! Constructors! Assignment

Working with Objects. Overview. This chapter covers. ! Overview! Properties and Fields! Initialization! Constructors! Assignment 4 Working with Objects 41 This chapter covers! Overview! Properties and Fields! Initialization! Constructors! Assignment Overview When you look around yourself, in your office; your city; or even the world,

More information

Carrera: Analista de Sistemas/Licenciatura en Sistemas. Asignatura: Programación Orientada a Objetos

Carrera: Analista de Sistemas/Licenciatura en Sistemas. Asignatura: Programación Orientada a Objetos Carrera: / Asignatura: Programación Orientada a Objetos REFACTORING EXERCISE WITH ECLIPSE - 2008- Observation: This refactoring exercise was extracted of the web site indicated in the section Reference

More information

CS61A Notes Week 6: Scheme1, Data Directed Programming You Are Scheme and don t let anyone tell you otherwise

CS61A Notes Week 6: Scheme1, Data Directed Programming You Are Scheme and don t let anyone tell you otherwise CS61A Notes Week 6: Scheme1, Data Directed Programming You Are Scheme and don t let anyone tell you otherwise If you re not already crazy about Scheme (and I m sure you are), then here s something to get

More information

Analysis of the Test Driven Development by Example

Analysis of the Test Driven Development by Example Computer Science and Applications 1 (2013) 5-13 Aleksandar Bulajic and Radoslav Stojic The Faculty of Information Technology, Metropolitan University, Belgrade, 11000, Serbia Received: June 18, 2013 /

More information

Software Engineering /48

Software Engineering /48 Software Engineering 1 /48 Topics 1. The Compilation Process and You 2. Polymorphism and Composition 3. Small Functions 4. Comments 2 /48 The Compilation Process and You 3 / 48 1. Intro - How do you turn

More information