COMP5911M Advanced Software Engineering Coursework 1
These exercises are based on material from the lectures and worksheets on refactoring. There are a total of 25 marks available. This coursework is worth 15% of your overall grade.
Exercises
1. Swing is a framework provided in the Java API to support the development of desktop graphical user interfaces1. Swing includes the class JTable, a GUI component that represents data in tabular form. The API documentation for this class is available at
https://docs.oracle.com/javase/10/docs/api/javax/swing/JTable.html
(a) What is the main code smell evident from studying the methods of JTable? Explain your
reasoning. [2 marks]
(b) Describe briefly how you could refactor this class to make it easier to work with. You do not need to go into great detail here, but you should identify any of the standard refactorings that might be useful, and indicate how they would be used in this context. Use the Catalog of Refactorings to guide you:
https://refactoring.guru/refactoring/catalog
[4 marks]
2. TheJavaAPIalsoprovidesaclassnamedBufferedImage,tosupportthecreationofimageprocessing applications in Java:
https://docs.oracle.com/javase/10/docs/api/java/awt/image/BufferedImage.html Study the documentation for the methods of this class, paying particular attention to the getRGB,
getSubimage and setRGB methods.
(a) What code smell is evident in these methods? [2 marks]
(b) Suggest a refactoring that would improve these methods, in particular. (Use the Catalog of Refactorings to help you choose.) Explain why this improves the class and write some fragments of Java source code to illustrate the improvement. [8 marks]
3. Download cwk1.zip from Minerva and unpack the archive into your cloned GitLab repository. This should give you a directory named cwk1 at the top level of your repository. This directory contains a Gradle-based project containing a small Java class named ArrayChecker.
(You should have already set up a GitLab account, as described in Worksheet 1. If you still dont have access to your repository, speak to Nick as soon as possible.)
(a) Identify the code smell that is evident in ArrayChecker. Describe briefly how you would refactor the class to remove the smell. [4 marks]
(b) Refactor the code in the manner described in (a). Make sure that the refactoring process is visible as a series of commits in your GitLab repository. Remember to run the provided unit tests before you start and at each intermediate step. You can do this via the Gradle wrapper (see the worksheets). At all stages, the tests should pass.
Note: when refactoring, dont focus simply on ArrayChecker. They may also be opportunities to improve the unit tests. . . [5 marks]
1Swing is no longer actively developed and has been largely superceded by JavaFX.
1
Submission
Your written answers should be in the form of a PDF file; do not submit a Word document or any other kind of editable format. Submit your PDF file via the link provided for this purpose in Minerva. If you attempt the refactoring for 3(b), make sure your all your commits have been pushed up to GitLab. The deadline for submission is 10.00 on 7 November 2019.
2
Reviews
There are no reviews yet.