| CompSci 308 Spring 2021 |
Advanced Software Design and Implementation |
The interface of a class is the one place where we assert all of the assumptions that a client may make about any instances of the class; the implementation encapsulates details about which no client may make assumptions. — Grady Booch
SonarQube combines a number of static code analysis tools to automatically generate issues by looking for certain features in your code (such as public instance variables) and we have created an app that helps organize and prioritize those issues to clarify why these issues are relevant to your design. It should be noted that this analysis in no way guarantees your code is well designed, it only helps find obvious potential flaws and brings them to your attention. For example, it is an obvious design flaw to have public instance variables, but you can still have a bad design even if all of your instance variables are private. While you are not required to remove all issues found by this tool, you should be prepared to justify why you left significant issues in your code (e.g., with comments near the lines flagged as issues in any of the reports).
As a team, use today's lab time to focus only on the project's design rather than adding new features, focusing your refactoring efforts on:
You will know your design is on the right track if your code:
In your Cell Society teams, complete the following activities today:
REFACTORING_DISCUSSION.md in the doc folder using Gitlab's markdown formatrefactoringLabrefactoringLab branch to your team's master branch so the changes can be compared and approved before being integrated At the end of class, use Gitlab's Merge Request to submit your group's refactored code from its separate branch, including your doc/REFACTORING_DISCUSSION.md file to the team repository.
Make sure the Title of your Merge Request is of the form "lab_refactoring - everyone's NetIDs".
Refactoring is the practice of updating a program to improve its design and maintainability without changing its current functionality significantly. An example of refactoring is creating a single method or class that replaces two or more sections of similar code because it reduces the amount of redundant code within the program and makes the code easier to debug and test. Since your project and team size has increased, we have created a tool that helps highlight basic design flaws to give places to start your refactoring. Note, IntelliJ also tries to do this with its yellow warning marks on the right edge of the editor window, but they tend be "lower level" than the ones SonarQube finds.
Examine the results of SonarQube's static analysis of your most recent master branch and, as a team, discuss how fixing each issue would improve the overall program design as well as which issues you think are the most important to work on first. Some issues may have easy fixes and some may require more thought or require more sweeping changes. For example, as we have discussed in class, sometimes removing duplicated code is as simple as creating a new method, sometimes it requires creating an inheritance hierarchy, sometimes generics is the right approach, or a new class or abstraction may be required.
To begin discussing the code's design, review the top issues found in your code using the following steps and record the results in your discussion file:
Note, the top issues on the Dashboard that are organized roughly in the following order:
For each of these kinds of issues, you can also see the complete list of issues in your project rather than just the top ones by selecting a specific file, colored and sized by how many issues it has, or by the category option at the bottom of the Dashboard (in its footer).
In your discussion file, describe why you chose to refactor the code as you did and what, if any, alternatives you considered.
As a reminder of some of the project specific design goals, here are a minimal set that every team is expected to reach:
public instance variables (also note, protected instance variables also break encapsulation and should be avoided, but public ones are simply poor design)public references to grid's data structure implementation (i.e., as a 2D array or a List of Lists) should appear in any public method signatureinstanceof checks (except in equals() methods)if or switch) per inheritance hierarchy can be used in the entire project and only for purposes of calling newimport javafx.XXX) to OpenJFX classes within your model classes (even javafx.scene.paint.Color)String.format() for dynamic information rather than '+'model, view, and configuration)Not every team will have all of the issues above, but every team has at least one of these issues.