Assignment 8: Refactoring Solved

$24.99 $18.99

For the assignment, you will need to find out information about refactoring patterns, which does not appear in the lecture slides. The following location is an excellent starting point:http://www.refactoring.com/catalog/index.html. 1. Consider the following two code fragments. Which fragment is more understandable? And why? (Hint: Think code smells) A. doublepotentialEnergy(double mass, double height) { return mass…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Categorys:

Description

5/5 – (2 votes)

For the assignment, you will need to find out information about refactoring patterns, which does not appear in the lecture slides. The following location is an excellent starting point:http://www.refactoring.com/catalog/index.html.

1. Consider the following two code fragments.

Which fragment is more understandable? And why? (Hint: Think code smells)

A.

doublepotentialEnergy(double mass, double height) {

return mass * height * 9.81;

}

B.

static final double g = 9.81;

doublepotentialEnergy(double mass, double height) {

return mass * g * height;

Assignment https://eclass.srv.ualberta.ca/mod/assign/view.php?id=3237750

Assignment https://eclass.srv.ualberta.ca/mod/assign/view.php?id=3237750

public intk(long i) {

return 10;

}

public intk(int i) {

return 20;

}

}

public class B extends A {

public static voidmain(String[] args) {

System.out.println(new A().k(2));

}

}

Which refactoring pattern has been applied to the first fragment to transform it into the second code fragment? Explain the impact (upon the results from function test) of the transformation.

Assignment 8: Refactoring Solved
$24.99 $18.99