Advanced Software Engineering Coursework 1 Analysis and Refactoring

Verified

Added on  2023/06/03

|5
|614
|367
Homework Assignment
AI Summary
This assignment analyzes two key Java classes, JTable and BufferedImage, within the context of advanced software engineering principles. The coursework begins by identifying a 'code smell' in JTable, a GUI component used for displaying tabular data, and then dissects its responsibilities, suggesting refactoring strategies to improve its maintainability and usability. It explores four distinct areas of responsibility, providing examples of method grouping. Furthermore, the assignment examines the BufferedImage class, focusing on potential issues related to exception handling (specifically ArrayIndexOutOfBoundsException) and proposes refactoring techniques to address these problems. The solution also delves into how the Java security package utilizes design patterns, such as those related to public/private keys, key generation, and message digests, illustrating their application in securing Java applications.
Document Page
Advanced Software Engineering
Coursework1
Student Name
email
Course
Date
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1.
2. a)
The main problem is with the default sorting. If the model structure of JTable is changed ,
RowFilter is not applied correctly, for example, if Row 0 is filtered out the sorting result
will be empty as in [1].
b)
Viewing of data
JTable does not store data but is used to display data from another source which could be a
database. The methods used for this responsibility include:
getTableHeader() to display table header.
addRowSelectionInterval() add rows to the table.
Editing
Several methods are used in perform this responsibility.
getEditingColumn() that returns the column that is currently being edited.
getEditingRow() returns the row containing the cell to be edited.
getEditorComponent() returning the component in the editing session.
editCellAt() edits cells at particular row and column.
Updating UI
The class also updates the user interfaces of the table as shown by the below methods.
updateUI() that returns a notification from manager that the L&F has changed
Printing Table
The class has a responsibility of printing table as shown in the methods below:
Print() to display printing method to print the table.
Print(JTable.PrintMode p) prints the table in a given printing mode.
Document Page
c)
The best refactoring to improve this class would be pulling up methods to the Superclass
instead of placing them in subclasses [5]. An example from the code below:
public class Table extends JTable implements TableModelListener {
public Table(TableModel tblm)
{
//new Methods here.
}
It would be better to use the methods from Superclass JTable instead of creating own
methods in subclass Table.
2 a)
The main issue with getRGB,getSubimage and setRGB is that the
ArrayOutOfBoundsException exception is not guaranteed to work correctly since explicit
bounds checking is not guaranteed.
B)
The best refactoring for the problems with explicit bound checking is replacing exception
with test as shown below [5]. Instead of using the following code to check the value of X
position, where ArrayIndexOutOfBoundException is used ,
double getValueForX (int x) {
try {
return _values[X];
} catch (ArrayIndexOutOfBoundsException e) {
Document Page
return 0;
}
}
use the following code to test what the user enters
double getValueForX (int X) {
if (X >= _values.length) return 0;
return _values[X];
}
3.How Java.security Makes use of Design Patterns
The Security package provides classes and interface that offer security. Public Key and
Private Key packages represent the private and public keys to be used for encryption.
KeyPairGenerator class is used to generate pairs of public and private keys. KeyStore.
[3]. InvalidKeyException generates invalid key exceptions when wrong keys are entered.
MessageDigest class provides applications with the message digest algorithm, [4].
DigestException generates message digest exception. GuardedObject class protects an
object from other objects.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Reference
[1]"Class JTable", Oracle, 2018.
[2]"Class BufferedImage", Oracle, 2018.
[3]"Package Java.security", Oracle, 2018.
[4]"How to Implement a Provider", Oracle, 2018.
[5]M. Fowler, "Catalog of
Refactorings", Refactoring, 2018.
chevron_up_icon
1 out of 5
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]