cv.pages
UG-Software Maintenance CS
Coursework
2017-18 Semester Autumn
Report
Software Maintenance
Understanding and improving other
people’s software
Name ZiXiang Xun
ID 4308922
G52SWM
word count: 987
Contents
1 The UML diagram
2 Types of code problem
2.1 Comments
2.2 Code Indentation
2.3 Variable declaration
2.4 Unused variables
2.5 Encapsulation of variables
3 Good coding practice
4 References
�2
1. The UML Diagram
Through the reverse engineering can obtain the UML diagram above. BatControl
class, BrickControl class and BallControl class extend to Control class, BreakoutApp
class extends to GameApplication class and BreakoutFactory implements to
TextEntityFactory interface. There are composition relationships between
BreakoutApp class and Breakout Factory class, BreakoutFactory class and
BatControl class, BreakoutFactory class and BrickControl class and BreakoutFactory
class and BallControl class, respectively. This is because BreakFactory class is a
factory that create Bat, Brick and Ball objects.This is a “contain” relationship and if
we delete the BreakFactory object the Bat, Brick and Ball objects which created in
BreakFactory class will also be automatically deleted. The same for BreakoutApp
class, in BreakoutApp class it create aBreakoutFactory object so there is a
composition relationship between BreakoutApp class and BreakoutFactory class too.
In addition, BreakoutApp create getBatControl() and getBallControl() methods as the
�3
methods’ type are BatControl class and BallControl class therefore there are
association relationships between them. It also use BrickControl class as
getControl() method’s parameter, so there is a dependency relationship between
them. At last, Both BreakoutApp and BreakoutFactory call the BreakoutType class as
a parameter, so there are dependency relationships between them.
�4
2. Types of code problem
2.1 Comments
Comments in the program is an important means of communication between
programmers and program readers. The application note specification is especially
important for the software itself and the software developer. Good comments can
reduce the maintenance cost of a software as much as possible, and almost no
software, maintained by the original developers throughout its life cycle. Good
comments specification allows developers to understand the code as soon as
possible. Good comment specification can maximize the efficiency of team
development. Long-term normative coding also allows developers to develop good
coding habits, and even exercise a more rigorous thinking skills.
Before the code is delivered to others or released, temporary or irrelevant comments
must be deleted to avoid confusion in future maintenance efforts.
In BreakControl Class:
In BatControl Class:
�5
These two sections of code have useless comments left when writing code, which is
not conducive to reading, writing and modifying, is unnecessary and difficult to
maintain. In order not to create problems for future developers, they should be
deleted.
The new code should be:
�6
2.2 Code Indentation
Code formatting is one of the most important aspects of programming and Code
indentation is a main part of the code formatting which is more aesthetic. If we follow
the correct style guidelines and indentation, then readers and further developers will
feel comfortable to read and understand the meaning of the code. During a team
development, a good code indentation can make other developers easier to modify
and enhance it. It also saves a lot of time on debugging, updating code and adding
new code.
In BreakoutFactory Class:
In BreakoutApp Class:
�7
In BreakoutApp Class:
The code showed above have the problem with non-standard code formatting,
Mainly code indentation problem. When an expression can not be written in one line,
it can be broken according to the following general rules:
– Broken after a comma
– Broken in front of an operator
– A new line should be aligned with the beginning of the same level of expression on
the previous line.
The new code should be :
�8
2.3 Variable declaration problem
Variable names can include uppercase letters and lowercase letters, the first
character should be lowercase, Words separated by capital letters. In order to
facilitate understanding, The variable name should be closed to the meaning of
variable.
In BallControl Class:
�9
In BallControl Class it create a PhysicsComponent variable named “g2”. This is
difficult to help further developers to understand the meaning of this variable and its
role. In addition, the variable”g2” is never been used. By contrast with BatControl
class, I think “g2” should be changed to “physics”.
The new code should be:
2.4 Unused Variables
In BrickControl class:
�10
Another important thing is that when finish programming, all the useless variables
and testing variables should be deleted. In order not to make the further programmer
confused, and it also can save memory space. If there are too many useless
variables, the further developers need to spend time figuring out which variables are
purposeful, which variables for testing, and which variables only waste time, this will
reducing the efficiency of team development. However, if the code is concise and all
irrelevant variables are removed, the risk of wasting unnecessary time on reviewing
code to understand it will be reduced.
The new code should be:
2.5 Encapsulation of variables
The benefit of encapsulation is that you can keep the invocation method invariant
and freely modify the structure of your classes without affecting the results of others.
Encapsulation also separates the attributes of the class into private and public
attributes. Private attributes are only called by the class itself, and public attributes
provide only one method for external calls. A good encapsulation is able to reduce
the coupling.
�11
In BatControlApp class:
Attributes in the BaControl class should use encapsulation because there are some
variables have the same names also appearing in other classes, it is safer to use
“private” to modify these variables and will not cause errors when calling variables.
The new code should be:
�12
3. Good coding practice
In BreakoutApp class:
The main role of the breakout class is to build the game environment, the “protected”
modified method can be called by other classes in the same package or by its
subclasses (extends). The code divide the “protected” modified method InitGame() into
several “private” modified methods and then only call these methods in the InitGame()
method. When InitGame() method is called, the function will achieved and programmers
do not know how it achieved, therefore enhancing the security of the code.
Word Count: 987
�13
4. References
Farrell, J. (2001) Make bad code good. Available at: https://www.javaworld.com/
article/2075129/testing-debugging/make-bad-code-good.html. (Accessed: 23 Mar
2001).
Shukla, V. (2013) Encapsulation With Example And Benefits In Java & OOP.
Available at: http://brevitaz.com/encapsulation-example-benefits-java/ (Accessed: 23
September 2013).
Neil (2017) The importance of indentation in programming. Available at: https://
blog.programminghub.io/blog/2017/06/07/importance-indentation-programming/.
(Accessed: 7 June 2017).
Pal, K. (2013) Importance of code indentation. Available at: http://mrbool.com/
importance-of-code-indentation/29079. (Accessed: 16 September 2013).
Singh, C. Java Access Modifiers – Public, Private, Protected & Default. Available at:
https://beginnersbook.com/2013/05/java-access-modifiers/.
Triosi, M. (2017) Useless comments can ruin your code reviews. Here’s how to erase
them. Available at: https://techbeacon.com/useless-comments-can-ruin-code-review-
heres-how-erase-them. (Accessed: 27 April 2017).
�14
https://www.javaworld.com/article/2075129/testing-debugging/make-bad-code-good.html
http://brevitaz.com/encapsulation-example-benefits-java/
https://blog.programminghub.io/blog/2017/06/07/importance-indentation-programming/
http://mrbool.com/importance-of-code-indentation/29079
https://beginnersbook.com/2013/05/java-access-modifiers/
https://techbeacon.com/useless-comments-can-ruin-code-review-heres-how-erase-them