0% found this document useful (0 votes)
14 views5 pages

University of Management and Technology: Software Re-Engineering

This document provides solutions to common code smells including duplicated code, long methods, long parameter lists, divergent change, short gun surgery, envy feature, data clumps, primitive obsession, switch statements, parallel inheritance hierarchies, lazy class, speculative generality, temporary fields, message chains, inappropriate intimacy, alternative classes with different interfaces, incomplete library class, refused bequest, and comments. Solutions involve techniques such as extracting methods, using inheritance, moving methods, inline classes, replacing parameters with objects, and improving class and method names for clarity.

Uploaded by

safiullahadam353
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

University of Management and Technology: Software Re-Engineering

This document provides solutions to common code smells including duplicated code, long methods, long parameter lists, divergent change, short gun surgery, envy feature, data clumps, primitive obsession, switch statements, parallel inheritance hierarchies, lazy class, speculative generality, temporary fields, message chains, inappropriate intimacy, alternative classes with different interfaces, incomplete library class, refused bequest, and comments. Solutions involve techniques such as extracting methods, using inheritance, moving methods, inline classes, replacing parameters with objects, and improving class and method names for clarity.

Uploaded by

safiullahadam353
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

University of Management and Technology

Software Re-Engineering
Assignment# 01

Name: Ahmad Waleed Shahzad


ID: F2019065218
Section: W2
Date: 7th Nov, 2022

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.

You might also like