$24
Exercise - 1: Code Review (20 Marks)
Code review is an important practice adopted by developers to ensure the quality of the code, as well as the growth of the developers involved. It can be an expensive process due the amount of time it requires, but the number of companies that employ this technique clearly indicates that the benefits of conducting code reviews clearly outweigh the cost.
Therefore, it is important for software engineering students to become familiar with this practice.
Please see some good resource:
https://smartbear.com/learn/code-review/best-practices-for-peer-code-review/
https://courses.cs.washington.edu/courses/cse403/13sp/lectures/10-codereviews.pdf
You are strongly encouraged to go beyond the provided resources and do additional reading on code reviews and software engineering best practices.
What to do:
Each student must:
• Conduct a code review for another student
• Subject his/her code to a review by another student
Students can choose to have ONE of the following 2 programs reviewed:
• The code for the tool shop developed in assignment 3
• The code developed for post-lab 4, exercise 3 (tic-tac-toe)
Please consider the following in your code review:
• Each review should take about 30 to 45 minutes.
• The review must review between 200 to 400 lines of code (but no more!).
• The reviewer must be careful to point out different code smells as discussed in class including:
o Issues related to naming and naming conventions o Spelling mistakes
o Violation of SOLID principles
o Issues with “overly complicated” code o Etc.
What to Hand in:
• Reviewers are to download the code review template from D2L and document their review. Only Reviewers submit the template (convert to PDF before submitting).
• Developers submit a reflection: list the most important lessons learned from your code review. Elaborate on each item briefly (Convert to PDF before submitting).
Exercise - 2: SOLID Principles (35 Marks)
Task 1) (10 marks) Consider the following classes in answering parts a and b.
Part a (3 marks) Which SOLID principle is this program violating? Briefly explain.
Part b (7 marks) If needed, re-write each class completely to remove the code smell in question. If not, simply write no change needed for a class.
Write any classes or interfaces you are adding to this program in this space:
abstract public class Vehicle {
abstract public String getVehicleType (); abstract public String getEngineType ();
}
//If this class needs to change, rewrite it //completely. If not, write: “No change needed”.
Page 4 of 5
public class Car extends Vehicle{
//If this class needs to change, rewrite it
//completely. If not, write: “No change needed”.
private String vehicleType;
private String engineType;
Car(String vType, String eType) {vehicleType
= vType; engineType = eType;
}
@Override
public String getVehicleType() {
return vehicleType;
}
@Override
public String getEngineType() {
return engineType;
}
}
public class Bicycle extends Vehicle{
//If this class needs to change, rewrite it
private String vehicleType;
//completely. If not, write: “No change needed”.
Bicycle(String vType) {
vehicleType = vType;
}
@Override
public String getVehicleType() {
return vehicleType;
}
@Override
public String getEngineType() {
return null;
}
}
Task 2) (15 marks) Consider the following classes in answering parts a, b, and c.
public class GraphicCreator {
public class Shape {
public void drawShape(Shape s) {
private int shapeType;
if (s.getShapeType() == 1)
drawSquare((Square) s);
Shape (int type){shapeType = type;}
else if (s.getShapeType() == 2)
public int
getShapeType
() {
drawCircle((Circle) s);
return shapeType;
}
}
public void drawCircle(Circle c) {//Some code. }
}
public void drawSquare(Square s) {//Some code. }
}
public class Circle extends Shape{Circle
public class Square extends Shape{Square
(){super(2);}
(){super(1);}
}
}
Page 5 of 5
Part a (5 marks) Draw the class diagram for the classes above. Make sure to include all fields and methods in your class diagram.
Part b (4 marks) Which SOLID principle is this program violating? Briefly explain.
Page 6 of 5
Part c (6 marks) Draw a class diagram for a proper design that removes the code smell in the above program. Clearly include all fields and methods in your class diagram.
What to hand in: Please submit your solutions in a pdf file for tasks 1 and 2.
Page 7 of 5