University of Management and Technology: Software Re-Engineering
University of Management and Technology: Software Re-Engineering
Software Re-Engineering
Assignment# 01
Submitted to:
Dr. Nosheen Qamar
Duplicated Code
Two code frameworks looks same. This occurs when there is same expression in two diff
methods of a same code.
Solution:
If duplicate code is in subclasses use Extract method by using Pull up Field.
If duplicate code is in two different classes:
Use consolidate conditional expression and Extract method to place a condition for any different
method this will make easy to differentiate them.
Long Method:
Method having too many lines of code, lengthy codes will make you ask questions about the
code.
Solution:
To reduce the length of a code use
Extract method
Create loops
Add functions
Replace method with method objects
Long parameter list:
One method having several parameters. Due to this classes become less independent of each
other.
Solution:
Replace parameters with Method call.
Use Parameter object.
Divergent change:
You have to make a-lot of unrelated changes when you just have to make change in a class.
Many changes in a single class.
Solution:
Use inheritance: super classes, subclasses.
Short gun Surgery:
It is same as divergent change but it is opposite to it. Same change in multiple classes.
Solution:
Move method.
Inline class.
Envy feature:
A method having access of data from another object instead of its own data.
Solution:
Extract method to split the method in different parts.
Move method.
Data clumps:
Same group of variables present in different parts of code. Move these clumps to their own
classes.
Solution:
Use Extract class to move these codes to their own classes.
Make a data class and put these fields in it.
Primitive Obsession:
In this code smell primitive data types are used in your code, as they are very general so not
much reliable.
Solution:
Use parameter objects.
Replace data value/ array with objects.
Switch statements:
Switch statements are hard to change in a sense that if you have to add a new condition you have
to find all the switch statements in your code and change them.
Solution:
Use polymorphism instead of conditions
Replace code type with subclasses
Parallel inheritance hierarchies:
When you create subclass of a class in your code you need to create a subclass for another class.
Lager hierarchy, harder to make changes.
Solution:
Make instance of one hierarchy referring to the other, then remove the hierarchy in referred
class.
Lazy class:
The classes that are not contributing enough to your code, there absence make no difference.
Solution:
Remove extra classes and their subclasses.
Speculative Generality
Code becomes hard to understand due to extra code which was written for future need and it is
never used.
Solution:
Remove extra parameters
Remove unnecessary functionalities my inline method.
Temporary field:
The code which is required only in few circumstances and it is useless out of those events, this
may cause your code hard to understand and use.
Solution:
All the temporary code should be placed in a separate class using class extraction.
Use null object for conditional code.
Message chains:
When a client request an object for a specific functionality and that object forward this request to
another object and so on. And if there is any change in the relationship it will create a mess.
Solution:
Remove message chain using Hide delegate.
Remove dependency
Inappropriate intimacy:
A class use functions and methods of another class whereas an ideal class should be independent
and should not have extra dependencies
Solution:
Use inheritance to make the dependency official.
Alternative classes with different interfaces:
Two classes have same functionality but different names. This will create duplicate functionality.
Solution:
Create super class and in this way the already existing classes and their functionalities will
become subclasses.
Incomplete library class:
With the passage of time libraries start to lack features and this leads to lack of functionality.
Solution:
Foreign method
Refused bequest:
Different superclass having completely different subclass. This leads to the problem that many
methods remain unused most of the time.
Solution:
Remove inheritance
Comments:
Code full of explanation comments. This makes the code length and fishy.
Solution:
Use better class name
Create separate method to explain any important code.