SlideShare a Scribd company logo
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 1
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 2
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 3
Before rushing into the design smells It is wise to make a
reasonable effort to refer to clean code,
Modularization, refactoring and
software metrics slides.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 4
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 5
https://www.researchgate.net/profile/Simon_Hacks/publication/338854879_Towards_a_Catalog_of
_Enterprise_Architecture_Smells/links/5e2ff4a34585152d156f7b2d/Towards-a-Catalog-of-
Enterprise-Architecture-Smells.pdf
http://www.tusharma.in/smells/DESIGN.html
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 6
 Introduction
 Abstraction Smells
 Encapsulation Smells
 Modularization Smells
 Hierarchy Smells
 Conclusions
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 7
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 8
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 9
 Technical debt is the additional work needed to
complete software development.
 Technical debt is the difference between what
was promised and what was actually delivered.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 10
 Technical Debt is regarded as a critical issue in terms of the negative
consequences such as increased software development cost, low
product quality, decreased maintainability.
 Technical Debt describes the delayed technical development activities
for getting short-term payoffs such as a timely release of a specific
software.
 Furthermore, Technical Debt is explained as the effect of immature
software artifacts, which requires extra effort on software maintenance
in the future.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 11
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 12
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 13
 Definition:
 Design smells are certain structures in the design that indicate violation of
fundamental design principles and negatively impact design quality.
 Bad smells are certain structures in code that indicate the violation of
fundamental design principles and negatively impact software quality.
 Examples:
 Design smells:
- Classes with multiple responsibilities,
- Cyclically dependent classes.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 14
 Architecture smells:
- Layering violations: Accesses from a lower level to a higher level layer,
- Tangled modules: Modules tightly coupled because of loops,
- Large interfaces: Components exposing large number of methods,
- In summary whatever violates modularity principles.
 Implementation smells:
- Loops that perform multiple tasks,
- Large methods,
- Complex conditional statements.
- In summary whatever violates clean code principles.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 15
1.Alternative Classes with Different
Interfaces
2.Broken Hierarchy
3.Broken Modularization
4.Cut and Paste Programming
5.Cyclic Hierarchy
6.Cyclically-dependent Modularization
7.Data Class
8.Data Clumps
9.Deep Hierarchy
10.Deficient Encapsulation
11.Divergent Change
12.Duplicate Abstraction
13.Feature Envy
14.Functional Decomposition
15.God Class
16. God Class
17.Golden Hammer
18.Hub-like Modularization
19.Imperative Abstraction
20.Inappropriate Intimacy
21.Incomplete Abstraction
22.Incomplete Library Class
23.Inheritance Hierarchies
Without Polymorphic
Assignments
24.Insufficient Modularization
25.Large Class
26.Lava Flow
27.Lazy Class
28.Leaky Encapsulation
29.List-like Inheritance Hierarchy
30.Message Chains
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 16
31. Missing Abstraction
32. Missing Encapsulation
33. Missing Hierarchy
34. Multifaceted Abstraction
35. Multipath Hierarchy
36. Obsolete Classes
37. Parallel Inheritance Hierarchies
38. Poltergeist
39. Primitive Obsession
40. Rebellious Hierarchy
41. Refused Bequest
42. Shotgun Surgery
43. Spaghetti Code
44. Speculative Generality
45. Speculative Hierarchy
46. Static Cycles in Dependency Graphs
47. Subclasses Do Not Redefine Methods
48. Swiss Army Knife
49. Switch Statement
50. The Blob
51. Too Deep Inheritance
Hierarchy
52. Tree-like Dependency Graph
53. Type Queries
54. Unexploited Encapsulation
55. Unfactored Hierarchy
56. Unhealthy Inheritance
Hierarchy
57. Unnecessary Abstraction
58. Unnecessary Hierarchy
59. Unutilized Abstraction
60. Visibility of Dependency
Graphs
61. Wide Hierarchy
http://www.tusharma.in/smells/DESIGN.html
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 17
 Most harmful smells in priority order :
- God Class (or Large Class);,
- Brain Method (or Long Method);
- Shotgun Surgery;
- Message Chains;
- Dispersed Coupling;
- Intensive Coupling;
- Feature Envy.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 18
 Metrics are used as a basis for automatic identification of code smells.
 Detection of smells requires a method to automatically derive thresholds for
design metrics.
Ref. JCodeOdor: A Software Quality Advisor Through Design Flaws
Detection
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 19
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 20
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 21
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 22
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 23
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 24
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 25
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 26
For Example
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 27
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 28
The four fundamental object oriented design principles are:
1. Abstraction:
 Distinguishes an object from all other kinds of objects,
 Provides conceptual boundaries, relative to the perspective of the
viewer.
2. Encapsulation:
 The process of compartmentalizing the elements of an abstraction that
constitute its structure and behavior;
 Serves to separate the contractual interface of an abstraction and its
implementation.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 29
3. Modularity
 Modularity is the property of a system that has been decomposed into
a set of cohesive and loosely coupled modules.
2. Inheritance:
 Hierarchy is a ranking or ordering of abstractions.
All design smells in object oriented design could be traced back to
violations of the above four principles.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 30
https://www.researchgate.net/publication/247152741_Towards_a_Principle-based_Classification_of_Structural_Design_Smells/figures?lo=1
Design Smells
Violation of O.O. design
Principles
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 31
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 32
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 33
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 34
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 35
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 36
Before rushing into the abstraction smells It is wise to make a
reasonable effort to know what the role of abstraction in
software engineering is and how it is modeled and
implemented.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 37
 Abstraction is the concept of representing something at high level,
without going into too much details
 Focus on “What”
 As indicated by English meaning, abstraction indicates “only idea” – not
associated with anything concrete.
 In other words, it focuses on what and factors out how something
should be done.
 Most of the programming languages like C++, C#, Java supports two
types of abstraction namely Control Abstraction and Data Abstraction.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 38
 Abstraction of behavior. Provides an easier, higher level API to
hide client from unnecessary execution details.
 In java, this can be achieved by using abstract keyword at
method and class level.
[codesnippet pb_margin_bottom=”yes” width=”1/1″ el_position=”first last”]
public abstract class Vehicle
{
public abstract void accelerate();
public abstract void doBreak();
public int getXPosition(){ // some implementation }
}
[/codesnippet]
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 39
 Any entity can be seen differently from different perspectives.
Car Abstraction with perspective of Vehicle Tracking System:
[codesnippet pb_margin_bottom=”yes” width=”1/1″
el_position=”first last”]
interface Trackable
{
int getXCoordinate();
int getYCoordinate();
}
[/codesnippet
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 40
Car Abstraction with perspective of Driver:
[codesnippet pb_margin_bottom=”yes” width=”1/1″ el_position=”first last”]
interface Drivable
{
void start();
void accelerate();
void reverse();
void doBreak();
String getSpeed();
void stop();
}
[/codesnippet]
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 41
 Data abstraction refers to defining the behavior of the data structure.
 Includes various data types provided by programming languages,
DBMS or language APIs.
 Data types in programming languages is the best data abstraction
example.
 DBMSs have abstractions of Table and View.
 Collection API’s Collection, List, Set and Map interfaces are
example of data abstractions.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 42
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 43
 Incomplete abstraction:
 An important abstract implementation is to create a cohesive and complete
abstraction.
 This bad smell is caused when the abstract does not support all
complementary or related methods.
 If an abstraction does not support related methods, it may affect the cohesion
and integrity of the abstraction.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 44
 Using a single method instead of a paired method
₋ For example, replace Enable() and Disable() with SetEnabled(bool), passing
true means enabled, and false means disabled.
 The JDK’s javax.swing.ButtonModel interface provides setGroup() method,
but does not provide the symmetric getGroup() method.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 45
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 46
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 47
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 48
 This smell arises when clump of data or encoded strings are used instead of
creating a class or interface.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 49
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 50
 ISBNs represented as 10-digit and 13-digit
forms consist of the elements: Prefix
Element, Registration, Group Element,
Registrant Element, Publication Element,
and Checksum.
₋ In the context of a library information
system, not encapsulating ISBN numbers as
class(es) indicates a Missing Abstraction
smell.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 51
 This smell arises when an operation is turned into a class.
 This smell manifests as a class that has only one method defined within the
class.
 Tools to detect this smell: Designite(for C#) DesigniteJava(for Java).
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 52
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 53
 This smell arises when an abstraction has more than one responsibility
assigned to it.
 Responsibility is the work or action that each part of your system, the
methods, the classes, the packages, the modules are assigned to do.
 Too much responsibility leads to coupling.
 Components with low cohesion are doing tasks that are not related to their
responsibilities.
 Tools to detect this smell: Designite(for C#) DesigniteJava(for Java).
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 54
 we have a User Class that we keep some info in there:
 Makes sense to keep only methods that set or get the
role, name, age properties
 Those checkAge, validateEmail, slugifyName look
strange for sure.
 That would actually make the class less cohesive.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 55
 This smell arises when an abstraction controls other abstractions in the
system.
 Also known as: “Brain class”.
 A Brain (or God) class tends to accumulate an excessive amount of
intelligence, usually in the form of several methods affected by
Brain Method.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 56
 Brain Methods tend to centralize the functionality of a class, an entire
subsystem, or sometimes even a whole system.
 The strategy for detecting this design flaw:
₋ Method is excessively large.
₋ Method has long conditional branches.
₋ Method has deep nesting
₋ Method uses too many variables.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 57
The Brain Method detection strategy.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 58
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 59
This is an important decision, and
requires guidance from good software
engineering principles. Refer to third
paragraph in page 14 of:
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 60
 What is the average number of operations (methods) per class?
 Beyond which number of code lines is a method too large?
Statistical thresholds of 45 Java and 37 C++systems
 Average Number of Methods (NOM) per class
 Average Lines of Code (LOC) per method (operation)
 Average Cyclomatic Number (CYCLO) per line of code (i.e., density of
branching points)
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 61
 Lower margin: AV G − ST DEV .
 Higher margin: AV G + ST DEV .
 Very high: (AV G+ST DEV )· 1.5,
o Example. We want to know what a high WMC (Weighted
Method Count) value is for a class written in Java.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 62
 This smell arises when an abstraction is left unused (either not directly used
or not reachable). This smell manifests in two forms:
₋ Unreferenced abstractions: Concrete classes that are not being used by
anyone.
₋ Orphan abstractions: Stand-alone interfaces/abstract classes that do not have
any subtypes.
 Also known as: “Classes with unused responsibility”
 Tools to detect this smell: Designite(for C#) DesigniteJava(for Java).
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 63
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 64
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 65
Before rushing into the encapsulation smells It is wise to make
a reasonable effort to know what the role of encapsulation in
software engineering is and how it is modeled and
implemented.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 66
 If a chunk of code can receive parameters and return values, then it can be
observed from the outside as a unit that receives input, does some
processing, and produces the desired output.
 eg.:
public static Account[] sort(Account[] account)
 You don’t need to know which sort of algorithm was used by the
programmer who implemented the method.
 The welcome consequences of encapsulation known as information and
implementation hiding is to enable changing the internal design and
implementation decisions, without affecting anyone on the outside.
encapsulation is the basis of modularity, which can help you
construct complex systems by combining smaller components
 Encapsulate : enclose in a capsule, capture the essence of.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 67
 Encapsulation is also known as information
hiding concept.
 The data and operations are combined into a
single unit.
 The only way to access data is through the
operations which are designed to operate on
the data.
 The data is not available to the external world.
 This concept may make the data safe and
secure from the external interventions.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 68
 Encapsulation is a means of managing access to an object’s members:
₋ Private: visible only within the class,
₋ Protected: visible within its class and any class inherited form it.
 Encapsulation reduces maintenance cost by minimizing scope of change.
 Self-encapsulation goes a step further, indicating that all internal access
to a data field should also go through accessor methods as well.
 The fields of an object should not be exposed publicity, instead access
from outside should be via the accessor methods (getter and setter) .
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 69
 Here's an example of a reasonably encapsulated java class
class Charge {…
private int units;
private double rate;
public Charge(int units, double rate)
{ this.units = units;
this.rate = rate; }
public int getUnits() { return units; }
public Money getAmount() { return Money.usd(units * rate); }
}
 Both fields are immutable. The units field is exposed to clients of the class via
a getter, but the rate field is only used internally, so doesn't need a getter.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 70
 Here is a version using slef-encapsulated:
class ChargeSE {…
private int units;
private double rate;
public ChargeSE(int units, double rate)
{ this.units = units;
this.rate = rate; }
public int getUnits() { return units; }
private double getRate() { return rate; }
public Money getAmount() {return Money.usd(getUnits() * getRate());}
}
 Self encapsulation means that getAmount needs to access both fields through
getters. This also means I have to add a getter for rate, which I should make private.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 71
 The role of encapsulation and information hiding metrics in identification
of smelly and faulty classes in software code.
 Each class should present its identity (i.e., its interface) by a set of
services, which have one single responsibility and which provide a
unique behavior. Otherwise, the class smells.
https://shodhganga.inflibnet.ac.in/bitstream/10603/176830/12/12_chapter%203.pdf
 Each class should present its identity (i.e., its interface) by a set of
services, which have one single responsibility and which provide a
unique behavior. Otherwise, the class smells.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 72
 Smell - Move field: the methods of another class seems to be
interested in a field of a class much more than the methods of the
class, containing the field.
 Smell – Data class: A class that has only properties and no methods is
a data class. Give life to data by adding methods that operate on the
data.
 Smell – Lazy method: Methods that neither aid code clarity nor
improve encapsulation. Use Inline Method refactoring to eliminate
such methods.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 73
 Data classes unnecessarily increase coupling.
 Their encapsulation is poor because they do not provide functionality.
 Encapsulation metrics are applied to detect data class smells.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 74
1. Weight of a Class (WOC)
o Definition:
o WOC =
𝑁𝑜.𝑛𝑜𝑛−𝑎𝑛𝑐𝑒𝑠𝑡𝑜𝑟 𝑚𝑒𝑡ℎ𝑜𝑑𝑠 𝑜𝑓 𝑎 𝑐𝑙𝑎𝑠𝑠
𝑇𝑜𝑡𝑎𝑙 𝑛𝑜.𝑚𝑒𝑚𝑏𝑒𝑟𝑠 𝑜𝑓 𝑡ℎ𝑒 𝑖𝑛𝑡𝑒𝑟𝑓𝑎𝑐𝑒,𝑒𝑥𝑐𝑙𝑢𝑑𝑖𝑛𝑔 𝑖𝑛ℎ𝑒𝑟𝑖𝑡𝑒𝑑 𝑚𝑒𝑚𝑏𝑒𝑟𝑠
o Interpretation: Well designed classes tend to have a WOC value of 1.0.
o Outliers: Classes with values between 0 and 0.33.
2. Number Of Public Attributes (NOPA)
 Definition: NOPA is the no. non-inherited attributes of a class.
 Interpretation: Classes with public data members violate encapsulation.
 Outliers: The top-ten classes, but not having NOPA values less than 5.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 75
3. Number Of Accessor Methods (NOAM)
 Definition: NOAM is the no. non-inherited accessor methods of a class.
 Interpretation: High NOAM value  part of the functionality of that class
is probably misplaced in one or more other classes..
 Outliers: The top-ten classes, but not having NOPM values less than 3.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 76
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 77
 Design metrics measuring different aspects of an object-oriented software:
 size (e.g., number of methods of a class);
 complexity (e.g., maximum nesting level of control structures);
 cohesion (e.g., tight class cohesion);
 coupling (e.g., number of calls to other classes in the system);
 encapsulation (e.g., number of public attributes of a class);
 inheritance (e.g., depth of inheritance tree).
 Impacts of the metrics on software quality
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 78
o Measure two aspects, one is encapsulation aspect and the other
one is complexity aspect. Here it is calculated at method and
attribute level:
 EMA: (Encapsulated methods and attributes)
- Methods and attributes which are not used by any other class.
 DMA: (Direct accessible methods and attributes)
- Incorporates only those methods and attributes, used by other
classes.
 TMA: (Total numbers of methods and attributes)
- Considers all the methods and attributes in a class.
ECC = ( 𝐸𝑀𝐴 + 𝐷𝑀𝐴 ) / 𝑇𝑀𝐴
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 79
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 80
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 81
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 82
 “When a class has a relatively large number of methods or complex methods
with more than one responsibilities, it violates the decomposition principle
because of inadequate abstraction. This violation is called insufficient
modularity smell.
 Interfaces are used to decouple dependencies. Direct dependencies are
created between classes when a method of a class calls the methods of
another class, or a class extends another class or aggregates objects of
another class.
 Its better to have code duplicates than to delay testing of a component
because required changes to a superclass or library class it depends on are
pending.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 83
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 84
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 85
• A bad smell in code
• Any symptom in the source code that possibly indicates a
deeper problem.
• The term is coined by Kent Beck.
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 86
 Problem: Name of the method or class does not succinctly
describe what the class is for, or what the method does.
 (e.g. When someone other than the developer looks at the code,
they don’t know what is going on)
 Solution: rename or rewrite it!
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 87
• Duplicated Code – identical or very similar code exists in more
than one location
• Long Method – method that has grown too large
• Large Class – class that has grown too large
• Long Parameter List – hard to understand/read
• Feature Envy – a class that uses methods of another class
excessively
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 88
• Large Class
• Large classes try to do too much, which reduces cohesion
• Long Parameter List
• hard to understand, can become inconsistent if the same parameter
chain is being passed from method to method
• Divergent Change
• symptom: one type of change requires changing one subset of
methods; another type of change requires changing another subset
• e.g., “I have to change these three methods every time I get a new
database.”
• Related to cohesion
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 89
• Shotgun Surgery
• a change requires lots of little changes in a lot of different
classes
• Feature Envy
• a method requires lots of information from some other class
• Move it closer!
• Data Clumps
• attributes that clump together (are used together) but are not
part of the same class
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 90
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 91
• Lazy Class
• A class that no longer “pays its way”
• e.g., may be a class that was downsized by a previous refactoring, or
represented planned functionality that did not pan out
• Speculative Generality
• “Oh, I think we need the ability to do this kind of thing someday”
• thus have all sorts of hooks and special cases to handle things that aren’t
required
• Temporary Field
• An attribute of an object is only set/used in certain circumstances;
• but an object should need all of its attributes
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 92
• Message Chains
• a client asks an object for another object and then asks that object
for another object etc.
• client depends on the structure of the navigation
• any change to the intermediate relationships requires a change to the client
• Middle Man
• If a class is delegating more than half its responsibilities to another
class, do you really need it? Involves trade-offs, some design patterns
encourage this (e.g., Decorator)
• Inappropriate Intimacy
• Pairs of classes that know too much about each other’s
implementation details (loss of encapsulation)
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 93
• Data Class (information holder)
• These are classes that have fields, getting and setting methods for the
fields, and nothing else; they are data holders, but objects should be
about data AND behavior
• Refused Bequest
• A subclass ignores most of the functionality provided by its superclass
• Subclass may not pass the “IS-A” test
• Comments (!)
• Comments are sometimes used to hide bad code
• “…comments are often used as a deodorant”(!)
4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 94

More Related Content

Similar to 8-bad-smells

FAIR Cookbook
FAIR Cookbook FAIR Cookbook
FAIR Cookbook
Susanna-Assunta Sansone
 
#mashcat: Evolving MarcEdit: Leveraging Semantic Data in MarcEdit
#mashcat: Evolving MarcEdit: Leveraging Semantic Data in MarcEdit#mashcat: Evolving MarcEdit: Leveraging Semantic Data in MarcEdit
#mashcat: Evolving MarcEdit: Leveraging Semantic Data in MarcEdit
Terry Reese
 
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024
Susanna-Assunta Sansone
 
1-requirements-elicitation
1-requirements-elicitation1-requirements-elicitation
1-requirements-elicitation
Morteza Zakeri
 
Catania Science Gateway Framework
Catania Science Gateway Framework Catania Science Gateway Framework
Catania Science Gateway Framework
riround
 
5-modular-design
5-modular-design5-modular-design
5-modular-design
Morteza Zakeri
 
DevoxxUK-2023 - Java Divergence.pdf
DevoxxUK-2023 - Java Divergence.pdfDevoxxUK-2023 - Java Divergence.pdf
DevoxxUK-2023 - Java Divergence.pdf
Felipe Yanaga
 
DevoxxUK-2023 - Java Divergence.pdf
DevoxxUK-2023 - Java Divergence.pdfDevoxxUK-2023 - Java Divergence.pdf
DevoxxUK-2023 - Java Divergence.pdf
FelipeYanaga1
 
Venice boats classification
Venice boats classificationVenice boats classification
Venice boats classification
Roberto Falconi
 
polysemy tag detect in tag sets
polysemy tag detect in tag setspolysemy tag detect in tag sets
polysemy tag detect in tag sets
saman Iftikhar
 
Linked Data in Learning Analytics Tools
Linked Data in Learning Analytics ToolsLinked Data in Learning Analytics Tools
Linked Data in Learning Analytics Tools
Mathieu d'Aquin
 
React HOCs, Context and Observables
React HOCs, Context and ObservablesReact HOCs, Context and Observables
React HOCs, Context and Observables
Trayan Iliev
 
Sakai uPortal Integration Options
Sakai uPortal Integration OptionsSakai uPortal Integration Options
Sakai uPortal Integration Options
John Lewis
 
Making Steaks from Sacred Cows
Making Steaks from Sacred CowsMaking Steaks from Sacred Cows
Making Steaks from Sacred Cows
Kevlin Henney
 
Research software and Dataverse
Research software and DataverseResearch software and Dataverse
Research software and Dataverse
philipdurbin
 
Unit No. 1 Introduction to Java.pptx
Unit No. 1 Introduction to Java.pptxUnit No. 1 Introduction to Java.pptx
Unit No. 1 Introduction to Java.pptx
DrYogeshDeshmukh1
 
Meetup deeplearningitalia-milano-valerio-morfino
Meetup deeplearningitalia-milano-valerio-morfinoMeetup deeplearningitalia-milano-valerio-morfino
Meetup deeplearningitalia-milano-valerio-morfino
Deep Learning Italia
 
FOSS Geoportal implementation in MESA
FOSS Geoportal  implementation in MESAFOSS Geoportal  implementation in MESA
FOSS Geoportal implementation in MESA
Luca Battistella
 
Front End Development for Backend Developers - GIDS 2019
Front End Development for Backend Developers - GIDS 2019Front End Development for Backend Developers - GIDS 2019
Front End Development for Backend Developers - GIDS 2019
Matt Raible
 
Criação de uma API RESTful Multitenat em Spring Boot e Oracle database utiliz...
Criação de uma API RESTful Multitenat em Spring Boot e Oracle database utiliz...Criação de uma API RESTful Multitenat em Spring Boot e Oracle database utiliz...
Criação de uma API RESTful Multitenat em Spring Boot e Oracle database utiliz...
Norberto Enomoto
 

Similar to 8-bad-smells (20)

FAIR Cookbook
FAIR Cookbook FAIR Cookbook
FAIR Cookbook
 
#mashcat: Evolving MarcEdit: Leveraging Semantic Data in MarcEdit
#mashcat: Evolving MarcEdit: Leveraging Semantic Data in MarcEdit#mashcat: Evolving MarcEdit: Leveraging Semantic Data in MarcEdit
#mashcat: Evolving MarcEdit: Leveraging Semantic Data in MarcEdit
 
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024
FAIR, FAIRsharing, FAIR Cookbook and ELIXIR - Sansone SA - Boston 2024
 
1-requirements-elicitation
1-requirements-elicitation1-requirements-elicitation
1-requirements-elicitation
 
Catania Science Gateway Framework
Catania Science Gateway Framework Catania Science Gateway Framework
Catania Science Gateway Framework
 
5-modular-design
5-modular-design5-modular-design
5-modular-design
 
DevoxxUK-2023 - Java Divergence.pdf
DevoxxUK-2023 - Java Divergence.pdfDevoxxUK-2023 - Java Divergence.pdf
DevoxxUK-2023 - Java Divergence.pdf
 
DevoxxUK-2023 - Java Divergence.pdf
DevoxxUK-2023 - Java Divergence.pdfDevoxxUK-2023 - Java Divergence.pdf
DevoxxUK-2023 - Java Divergence.pdf
 
Venice boats classification
Venice boats classificationVenice boats classification
Venice boats classification
 
polysemy tag detect in tag sets
polysemy tag detect in tag setspolysemy tag detect in tag sets
polysemy tag detect in tag sets
 
Linked Data in Learning Analytics Tools
Linked Data in Learning Analytics ToolsLinked Data in Learning Analytics Tools
Linked Data in Learning Analytics Tools
 
React HOCs, Context and Observables
React HOCs, Context and ObservablesReact HOCs, Context and Observables
React HOCs, Context and Observables
 
Sakai uPortal Integration Options
Sakai uPortal Integration OptionsSakai uPortal Integration Options
Sakai uPortal Integration Options
 
Making Steaks from Sacred Cows
Making Steaks from Sacred CowsMaking Steaks from Sacred Cows
Making Steaks from Sacred Cows
 
Research software and Dataverse
Research software and DataverseResearch software and Dataverse
Research software and Dataverse
 
Unit No. 1 Introduction to Java.pptx
Unit No. 1 Introduction to Java.pptxUnit No. 1 Introduction to Java.pptx
Unit No. 1 Introduction to Java.pptx
 
Meetup deeplearningitalia-milano-valerio-morfino
Meetup deeplearningitalia-milano-valerio-morfinoMeetup deeplearningitalia-milano-valerio-morfino
Meetup deeplearningitalia-milano-valerio-morfino
 
FOSS Geoportal implementation in MESA
FOSS Geoportal  implementation in MESAFOSS Geoportal  implementation in MESA
FOSS Geoportal implementation in MESA
 
Front End Development for Backend Developers - GIDS 2019
Front End Development for Backend Developers - GIDS 2019Front End Development for Backend Developers - GIDS 2019
Front End Development for Backend Developers - GIDS 2019
 
Criação de uma API RESTful Multitenat em Spring Boot e Oracle database utiliz...
Criação de uma API RESTful Multitenat em Spring Boot e Oracle database utiliz...Criação de uma API RESTful Multitenat em Spring Boot e Oracle database utiliz...
Criação de uma API RESTful Multitenat em Spring Boot e Oracle database utiliz...
 

More from Morteza Zakeri

Antlr part3 getting_started_in_c_sharp
Antlr part3 getting_started_in_c_sharpAntlr part3 getting_started_in_c_sharp
Antlr part3 getting_started_in_c_sharp
Morteza Zakeri
 
Antlr part1 introduction
Antlr part1 introductionAntlr part1 introduction
Antlr part1 introduction
Morteza Zakeri
 
Antlr part2 getting_started_in_java
Antlr part2 getting_started_in_javaAntlr part2 getting_started_in_java
Antlr part2 getting_started_in_java
Morteza Zakeri
 
3-use-casemodelling
3-use-casemodelling3-use-casemodelling
3-use-casemodelling
Morteza Zakeri
 
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...
Morteza Zakeri
 
Internet of Things: Middle-ware Platforms, Security, and Intrusion Detection
Internet of Things: Middle-ware Platforms, Security, and Intrusion DetectionInternet of Things: Middle-ware Platforms, Security, and Intrusion Detection
Internet of Things: Middle-ware Platforms, Security, and Intrusion Detection
Morteza Zakeri
 
Community Detection with Genetic Algorithm
Community Detection with Genetic AlgorithmCommunity Detection with Genetic Algorithm
Community Detection with Genetic Algorithm
Morteza Zakeri
 
SpotifyX Architectural Review
SpotifyX Architectural ReviewSpotifyX Architectural Review
SpotifyX Architectural Review
Morteza Zakeri
 
An overview of anomaly detection techniques
An overview of anomaly detection techniquesAn overview of anomaly detection techniques
An overview of anomaly detection techniques
Morteza Zakeri
 
SQLite and object-relational mapping in Java
SQLite and object-relational mapping in JavaSQLite and object-relational mapping in Java
SQLite and object-relational mapping in Java
Morteza Zakeri
 
Apache Mesos: Architecture, Design and Code Review
Apache Mesos: Architecture, Design and Code ReviewApache Mesos: Architecture, Design and Code Review
Apache Mesos: Architecture, Design and Code Review
Morteza Zakeri
 
یادگیری توالی به توالی با شبکه های عصبی
یادگیری توالی به توالی با شبکه های عصبییادگیری توالی به توالی با شبکه های عصبی
یادگیری توالی به توالی با شبکه های عصبی
Morteza Zakeri
 
Sequence to sequence learning with neural networks
Sequence to sequence learning with neural networksSequence to sequence learning with neural networks
Sequence to sequence learning with neural networks
Morteza Zakeri
 
Bridge Management System Using NoSQL Solutions
Bridge Management System Using NoSQL SolutionsBridge Management System Using NoSQL Solutions
Bridge Management System Using NoSQL Solutions
Morteza Zakeri
 
Extracting architectural model of software from source code
Extracting architectural model of software from source codeExtracting architectural model of software from source code
Extracting architectural model of software from source code
Morteza Zakeri
 
Software Fault Avoidance in Implementation
Software Fault Avoidance in ImplementationSoftware Fault Avoidance in Implementation
Software Fault Avoidance in Implementation
Morteza Zakeri
 
Introduction to Apache Mesos
Introduction to Apache MesosIntroduction to Apache Mesos
Introduction to Apache Mesos
Morteza Zakeri
 
Introduction to Oracle Grid Engine
Introduction to Oracle Grid Engine Introduction to Oracle Grid Engine
Introduction to Oracle Grid Engine
Morteza Zakeri
 
Introduction to Web Programming: PHP vs ASP.NET
Introduction to Web Programming: PHP vs ASP.NETIntroduction to Web Programming: PHP vs ASP.NET
Introduction to Web Programming: PHP vs ASP.NET
Morteza Zakeri
 
Tutorialspoint UI Analysis
Tutorialspoint UI AnalysisTutorialspoint UI Analysis
Tutorialspoint UI Analysis
Morteza Zakeri
 

More from Morteza Zakeri (20)

Antlr part3 getting_started_in_c_sharp
Antlr part3 getting_started_in_c_sharpAntlr part3 getting_started_in_c_sharp
Antlr part3 getting_started_in_c_sharp
 
Antlr part1 introduction
Antlr part1 introductionAntlr part1 introduction
Antlr part1 introduction
 
Antlr part2 getting_started_in_java
Antlr part2 getting_started_in_javaAntlr part2 getting_started_in_java
Antlr part2 getting_started_in_java
 
3-use-casemodelling
3-use-casemodelling3-use-casemodelling
3-use-casemodelling
 
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...
Analysis of Social Phenomena Using Machine Learning Techniques: A Mixed Resea...
 
Internet of Things: Middle-ware Platforms, Security, and Intrusion Detection
Internet of Things: Middle-ware Platforms, Security, and Intrusion DetectionInternet of Things: Middle-ware Platforms, Security, and Intrusion Detection
Internet of Things: Middle-ware Platforms, Security, and Intrusion Detection
 
Community Detection with Genetic Algorithm
Community Detection with Genetic AlgorithmCommunity Detection with Genetic Algorithm
Community Detection with Genetic Algorithm
 
SpotifyX Architectural Review
SpotifyX Architectural ReviewSpotifyX Architectural Review
SpotifyX Architectural Review
 
An overview of anomaly detection techniques
An overview of anomaly detection techniquesAn overview of anomaly detection techniques
An overview of anomaly detection techniques
 
SQLite and object-relational mapping in Java
SQLite and object-relational mapping in JavaSQLite and object-relational mapping in Java
SQLite and object-relational mapping in Java
 
Apache Mesos: Architecture, Design and Code Review
Apache Mesos: Architecture, Design and Code ReviewApache Mesos: Architecture, Design and Code Review
Apache Mesos: Architecture, Design and Code Review
 
یادگیری توالی به توالی با شبکه های عصبی
یادگیری توالی به توالی با شبکه های عصبییادگیری توالی به توالی با شبکه های عصبی
یادگیری توالی به توالی با شبکه های عصبی
 
Sequence to sequence learning with neural networks
Sequence to sequence learning with neural networksSequence to sequence learning with neural networks
Sequence to sequence learning with neural networks
 
Bridge Management System Using NoSQL Solutions
Bridge Management System Using NoSQL SolutionsBridge Management System Using NoSQL Solutions
Bridge Management System Using NoSQL Solutions
 
Extracting architectural model of software from source code
Extracting architectural model of software from source codeExtracting architectural model of software from source code
Extracting architectural model of software from source code
 
Software Fault Avoidance in Implementation
Software Fault Avoidance in ImplementationSoftware Fault Avoidance in Implementation
Software Fault Avoidance in Implementation
 
Introduction to Apache Mesos
Introduction to Apache MesosIntroduction to Apache Mesos
Introduction to Apache Mesos
 
Introduction to Oracle Grid Engine
Introduction to Oracle Grid Engine Introduction to Oracle Grid Engine
Introduction to Oracle Grid Engine
 
Introduction to Web Programming: PHP vs ASP.NET
Introduction to Web Programming: PHP vs ASP.NETIntroduction to Web Programming: PHP vs ASP.NET
Introduction to Web Programming: PHP vs ASP.NET
 
Tutorialspoint UI Analysis
Tutorialspoint UI AnalysisTutorialspoint UI Analysis
Tutorialspoint UI Analysis
 

Recently uploaded

Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 

Recently uploaded (20)

Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 

8-bad-smells

  • 1. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 1
  • 2. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 2
  • 3. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 3 Before rushing into the design smells It is wise to make a reasonable effort to refer to clean code, Modularization, refactoring and software metrics slides.
  • 4. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 4
  • 5. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 5 https://www.researchgate.net/profile/Simon_Hacks/publication/338854879_Towards_a_Catalog_of _Enterprise_Architecture_Smells/links/5e2ff4a34585152d156f7b2d/Towards-a-Catalog-of- Enterprise-Architecture-Smells.pdf http://www.tusharma.in/smells/DESIGN.html
  • 6. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 6  Introduction  Abstraction Smells  Encapsulation Smells  Modularization Smells  Hierarchy Smells  Conclusions
  • 7. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 7
  • 8. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 8
  • 9. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 9  Technical debt is the additional work needed to complete software development.  Technical debt is the difference between what was promised and what was actually delivered.
  • 10. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 10  Technical Debt is regarded as a critical issue in terms of the negative consequences such as increased software development cost, low product quality, decreased maintainability.  Technical Debt describes the delayed technical development activities for getting short-term payoffs such as a timely release of a specific software.  Furthermore, Technical Debt is explained as the effect of immature software artifacts, which requires extra effort on software maintenance in the future.
  • 11. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 11
  • 12. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 12
  • 13. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 13  Definition:  Design smells are certain structures in the design that indicate violation of fundamental design principles and negatively impact design quality.  Bad smells are certain structures in code that indicate the violation of fundamental design principles and negatively impact software quality.  Examples:  Design smells: - Classes with multiple responsibilities, - Cyclically dependent classes.
  • 14. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 14  Architecture smells: - Layering violations: Accesses from a lower level to a higher level layer, - Tangled modules: Modules tightly coupled because of loops, - Large interfaces: Components exposing large number of methods, - In summary whatever violates modularity principles.  Implementation smells: - Loops that perform multiple tasks, - Large methods, - Complex conditional statements. - In summary whatever violates clean code principles.
  • 15. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 15 1.Alternative Classes with Different Interfaces 2.Broken Hierarchy 3.Broken Modularization 4.Cut and Paste Programming 5.Cyclic Hierarchy 6.Cyclically-dependent Modularization 7.Data Class 8.Data Clumps 9.Deep Hierarchy 10.Deficient Encapsulation 11.Divergent Change 12.Duplicate Abstraction 13.Feature Envy 14.Functional Decomposition 15.God Class 16. God Class 17.Golden Hammer 18.Hub-like Modularization 19.Imperative Abstraction 20.Inappropriate Intimacy 21.Incomplete Abstraction 22.Incomplete Library Class 23.Inheritance Hierarchies Without Polymorphic Assignments 24.Insufficient Modularization 25.Large Class 26.Lava Flow 27.Lazy Class 28.Leaky Encapsulation 29.List-like Inheritance Hierarchy 30.Message Chains
  • 16. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 16 31. Missing Abstraction 32. Missing Encapsulation 33. Missing Hierarchy 34. Multifaceted Abstraction 35. Multipath Hierarchy 36. Obsolete Classes 37. Parallel Inheritance Hierarchies 38. Poltergeist 39. Primitive Obsession 40. Rebellious Hierarchy 41. Refused Bequest 42. Shotgun Surgery 43. Spaghetti Code 44. Speculative Generality 45. Speculative Hierarchy 46. Static Cycles in Dependency Graphs 47. Subclasses Do Not Redefine Methods 48. Swiss Army Knife 49. Switch Statement 50. The Blob 51. Too Deep Inheritance Hierarchy 52. Tree-like Dependency Graph 53. Type Queries 54. Unexploited Encapsulation 55. Unfactored Hierarchy 56. Unhealthy Inheritance Hierarchy 57. Unnecessary Abstraction 58. Unnecessary Hierarchy 59. Unutilized Abstraction 60. Visibility of Dependency Graphs 61. Wide Hierarchy http://www.tusharma.in/smells/DESIGN.html
  • 17. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 17  Most harmful smells in priority order : - God Class (or Large Class);, - Brain Method (or Long Method); - Shotgun Surgery; - Message Chains; - Dispersed Coupling; - Intensive Coupling; - Feature Envy.
  • 18. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 18  Metrics are used as a basis for automatic identification of code smells.  Detection of smells requires a method to automatically derive thresholds for design metrics. Ref. JCodeOdor: A Software Quality Advisor Through Design Flaws Detection
  • 19. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 19
  • 20. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 20
  • 21. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 21
  • 22. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 22
  • 23. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 23
  • 24. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 24
  • 25. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 25
  • 26. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 26 For Example
  • 27. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 27
  • 28. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 28 The four fundamental object oriented design principles are: 1. Abstraction:  Distinguishes an object from all other kinds of objects,  Provides conceptual boundaries, relative to the perspective of the viewer. 2. Encapsulation:  The process of compartmentalizing the elements of an abstraction that constitute its structure and behavior;  Serves to separate the contractual interface of an abstraction and its implementation.
  • 29. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 29 3. Modularity  Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules. 2. Inheritance:  Hierarchy is a ranking or ordering of abstractions. All design smells in object oriented design could be traced back to violations of the above four principles.
  • 30. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 30 https://www.researchgate.net/publication/247152741_Towards_a_Principle-based_Classification_of_Structural_Design_Smells/figures?lo=1 Design Smells Violation of O.O. design Principles
  • 31. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 31
  • 32. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 32
  • 33. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 33
  • 34. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 34
  • 35. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 35
  • 36. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 36 Before rushing into the abstraction smells It is wise to make a reasonable effort to know what the role of abstraction in software engineering is and how it is modeled and implemented.
  • 37. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 37  Abstraction is the concept of representing something at high level, without going into too much details  Focus on “What”  As indicated by English meaning, abstraction indicates “only idea” – not associated with anything concrete.  In other words, it focuses on what and factors out how something should be done.  Most of the programming languages like C++, C#, Java supports two types of abstraction namely Control Abstraction and Data Abstraction.
  • 38. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 38  Abstraction of behavior. Provides an easier, higher level API to hide client from unnecessary execution details.  In java, this can be achieved by using abstract keyword at method and class level. [codesnippet pb_margin_bottom=”yes” width=”1/1″ el_position=”first last”] public abstract class Vehicle { public abstract void accelerate(); public abstract void doBreak(); public int getXPosition(){ // some implementation } } [/codesnippet]
  • 39. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 39  Any entity can be seen differently from different perspectives. Car Abstraction with perspective of Vehicle Tracking System: [codesnippet pb_margin_bottom=”yes” width=”1/1″ el_position=”first last”] interface Trackable { int getXCoordinate(); int getYCoordinate(); } [/codesnippet
  • 40. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 40 Car Abstraction with perspective of Driver: [codesnippet pb_margin_bottom=”yes” width=”1/1″ el_position=”first last”] interface Drivable { void start(); void accelerate(); void reverse(); void doBreak(); String getSpeed(); void stop(); } [/codesnippet]
  • 41. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 41  Data abstraction refers to defining the behavior of the data structure.  Includes various data types provided by programming languages, DBMS or language APIs.  Data types in programming languages is the best data abstraction example.  DBMSs have abstractions of Table and View.  Collection API’s Collection, List, Set and Map interfaces are example of data abstractions.
  • 42. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 42
  • 43. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 43  Incomplete abstraction:  An important abstract implementation is to create a cohesive and complete abstraction.  This bad smell is caused when the abstract does not support all complementary or related methods.  If an abstraction does not support related methods, it may affect the cohesion and integrity of the abstraction.
  • 44. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 44  Using a single method instead of a paired method ₋ For example, replace Enable() and Disable() with SetEnabled(bool), passing true means enabled, and false means disabled.  The JDK’s javax.swing.ButtonModel interface provides setGroup() method, but does not provide the symmetric getGroup() method.
  • 45. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 45
  • 46. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 46
  • 47. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 47
  • 48. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 48  This smell arises when clump of data or encoded strings are used instead of creating a class or interface.
  • 49. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 49
  • 50. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 50  ISBNs represented as 10-digit and 13-digit forms consist of the elements: Prefix Element, Registration, Group Element, Registrant Element, Publication Element, and Checksum. ₋ In the context of a library information system, not encapsulating ISBN numbers as class(es) indicates a Missing Abstraction smell.
  • 51. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 51  This smell arises when an operation is turned into a class.  This smell manifests as a class that has only one method defined within the class.  Tools to detect this smell: Designite(for C#) DesigniteJava(for Java).
  • 52. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 52
  • 53. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 53  This smell arises when an abstraction has more than one responsibility assigned to it.  Responsibility is the work or action that each part of your system, the methods, the classes, the packages, the modules are assigned to do.  Too much responsibility leads to coupling.  Components with low cohesion are doing tasks that are not related to their responsibilities.  Tools to detect this smell: Designite(for C#) DesigniteJava(for Java).
  • 54. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 54  we have a User Class that we keep some info in there:  Makes sense to keep only methods that set or get the role, name, age properties  Those checkAge, validateEmail, slugifyName look strange for sure.  That would actually make the class less cohesive.
  • 55. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 55  This smell arises when an abstraction controls other abstractions in the system.  Also known as: “Brain class”.  A Brain (or God) class tends to accumulate an excessive amount of intelligence, usually in the form of several methods affected by Brain Method.
  • 56. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 56  Brain Methods tend to centralize the functionality of a class, an entire subsystem, or sometimes even a whole system.  The strategy for detecting this design flaw: ₋ Method is excessively large. ₋ Method has long conditional branches. ₋ Method has deep nesting ₋ Method uses too many variables.
  • 57. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 57 The Brain Method detection strategy.
  • 58. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 58
  • 59. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 59 This is an important decision, and requires guidance from good software engineering principles. Refer to third paragraph in page 14 of:
  • 60. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 60  What is the average number of operations (methods) per class?  Beyond which number of code lines is a method too large? Statistical thresholds of 45 Java and 37 C++systems  Average Number of Methods (NOM) per class  Average Lines of Code (LOC) per method (operation)  Average Cyclomatic Number (CYCLO) per line of code (i.e., density of branching points)
  • 61. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 61  Lower margin: AV G − ST DEV .  Higher margin: AV G + ST DEV .  Very high: (AV G+ST DEV )· 1.5, o Example. We want to know what a high WMC (Weighted Method Count) value is for a class written in Java.
  • 62. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 62  This smell arises when an abstraction is left unused (either not directly used or not reachable). This smell manifests in two forms: ₋ Unreferenced abstractions: Concrete classes that are not being used by anyone. ₋ Orphan abstractions: Stand-alone interfaces/abstract classes that do not have any subtypes.  Also known as: “Classes with unused responsibility”  Tools to detect this smell: Designite(for C#) DesigniteJava(for Java).
  • 63. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 63
  • 64. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 64
  • 65. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 65 Before rushing into the encapsulation smells It is wise to make a reasonable effort to know what the role of encapsulation in software engineering is and how it is modeled and implemented.
  • 66. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 66  If a chunk of code can receive parameters and return values, then it can be observed from the outside as a unit that receives input, does some processing, and produces the desired output.  eg.: public static Account[] sort(Account[] account)  You don’t need to know which sort of algorithm was used by the programmer who implemented the method.  The welcome consequences of encapsulation known as information and implementation hiding is to enable changing the internal design and implementation decisions, without affecting anyone on the outside. encapsulation is the basis of modularity, which can help you construct complex systems by combining smaller components  Encapsulate : enclose in a capsule, capture the essence of.
  • 67. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 67  Encapsulation is also known as information hiding concept.  The data and operations are combined into a single unit.  The only way to access data is through the operations which are designed to operate on the data.  The data is not available to the external world.  This concept may make the data safe and secure from the external interventions.
  • 68. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 68  Encapsulation is a means of managing access to an object’s members: ₋ Private: visible only within the class, ₋ Protected: visible within its class and any class inherited form it.  Encapsulation reduces maintenance cost by minimizing scope of change.  Self-encapsulation goes a step further, indicating that all internal access to a data field should also go through accessor methods as well.  The fields of an object should not be exposed publicity, instead access from outside should be via the accessor methods (getter and setter) .
  • 69. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 69  Here's an example of a reasonably encapsulated java class class Charge {… private int units; private double rate; public Charge(int units, double rate) { this.units = units; this.rate = rate; } public int getUnits() { return units; } public Money getAmount() { return Money.usd(units * rate); } }  Both fields are immutable. The units field is exposed to clients of the class via a getter, but the rate field is only used internally, so doesn't need a getter.
  • 70. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 70  Here is a version using slef-encapsulated: class ChargeSE {… private int units; private double rate; public ChargeSE(int units, double rate) { this.units = units; this.rate = rate; } public int getUnits() { return units; } private double getRate() { return rate; } public Money getAmount() {return Money.usd(getUnits() * getRate());} }  Self encapsulation means that getAmount needs to access both fields through getters. This also means I have to add a getter for rate, which I should make private.
  • 71. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 71  The role of encapsulation and information hiding metrics in identification of smelly and faulty classes in software code.  Each class should present its identity (i.e., its interface) by a set of services, which have one single responsibility and which provide a unique behavior. Otherwise, the class smells. https://shodhganga.inflibnet.ac.in/bitstream/10603/176830/12/12_chapter%203.pdf  Each class should present its identity (i.e., its interface) by a set of services, which have one single responsibility and which provide a unique behavior. Otherwise, the class smells.
  • 72. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 72  Smell - Move field: the methods of another class seems to be interested in a field of a class much more than the methods of the class, containing the field.  Smell – Data class: A class that has only properties and no methods is a data class. Give life to data by adding methods that operate on the data.  Smell – Lazy method: Methods that neither aid code clarity nor improve encapsulation. Use Inline Method refactoring to eliminate such methods.
  • 73. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 73  Data classes unnecessarily increase coupling.  Their encapsulation is poor because they do not provide functionality.  Encapsulation metrics are applied to detect data class smells.
  • 74. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 74 1. Weight of a Class (WOC) o Definition: o WOC = 𝑁𝑜.𝑛𝑜𝑛−𝑎𝑛𝑐𝑒𝑠𝑡𝑜𝑟 𝑚𝑒𝑡ℎ𝑜𝑑𝑠 𝑜𝑓 𝑎 𝑐𝑙𝑎𝑠𝑠 𝑇𝑜𝑡𝑎𝑙 𝑛𝑜.𝑚𝑒𝑚𝑏𝑒𝑟𝑠 𝑜𝑓 𝑡ℎ𝑒 𝑖𝑛𝑡𝑒𝑟𝑓𝑎𝑐𝑒,𝑒𝑥𝑐𝑙𝑢𝑑𝑖𝑛𝑔 𝑖𝑛ℎ𝑒𝑟𝑖𝑡𝑒𝑑 𝑚𝑒𝑚𝑏𝑒𝑟𝑠 o Interpretation: Well designed classes tend to have a WOC value of 1.0. o Outliers: Classes with values between 0 and 0.33. 2. Number Of Public Attributes (NOPA)  Definition: NOPA is the no. non-inherited attributes of a class.  Interpretation: Classes with public data members violate encapsulation.  Outliers: The top-ten classes, but not having NOPA values less than 5.
  • 75. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 75 3. Number Of Accessor Methods (NOAM)  Definition: NOAM is the no. non-inherited accessor methods of a class.  Interpretation: High NOAM value  part of the functionality of that class is probably misplaced in one or more other classes..  Outliers: The top-ten classes, but not having NOPM values less than 3.
  • 76. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 76
  • 77. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 77  Design metrics measuring different aspects of an object-oriented software:  size (e.g., number of methods of a class);  complexity (e.g., maximum nesting level of control structures);  cohesion (e.g., tight class cohesion);  coupling (e.g., number of calls to other classes in the system);  encapsulation (e.g., number of public attributes of a class);  inheritance (e.g., depth of inheritance tree).  Impacts of the metrics on software quality
  • 78. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 78 o Measure two aspects, one is encapsulation aspect and the other one is complexity aspect. Here it is calculated at method and attribute level:  EMA: (Encapsulated methods and attributes) - Methods and attributes which are not used by any other class.  DMA: (Direct accessible methods and attributes) - Incorporates only those methods and attributes, used by other classes.  TMA: (Total numbers of methods and attributes) - Considers all the methods and attributes in a class. ECC = ( 𝐸𝑀𝐴 + 𝐷𝑀𝐴 ) / 𝑇𝑀𝐴
  • 79. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 79
  • 80. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 80
  • 81. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 81
  • 82. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 82  “When a class has a relatively large number of methods or complex methods with more than one responsibilities, it violates the decomposition principle because of inadequate abstraction. This violation is called insufficient modularity smell.  Interfaces are used to decouple dependencies. Direct dependencies are created between classes when a method of a class calls the methods of another class, or a class extends another class or aggregates objects of another class.  Its better to have code duplicates than to delay testing of a component because required changes to a superclass or library class it depends on are pending.
  • 83. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 83
  • 84. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 84
  • 85. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 85 • A bad smell in code • Any symptom in the source code that possibly indicates a deeper problem. • The term is coined by Kent Beck.
  • 86. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 86  Problem: Name of the method or class does not succinctly describe what the class is for, or what the method does.  (e.g. When someone other than the developer looks at the code, they don’t know what is going on)  Solution: rename or rewrite it!
  • 87. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 87 • Duplicated Code – identical or very similar code exists in more than one location • Long Method – method that has grown too large • Large Class – class that has grown too large • Long Parameter List – hard to understand/read • Feature Envy – a class that uses methods of another class excessively
  • 88. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 88 • Large Class • Large classes try to do too much, which reduces cohesion • Long Parameter List • hard to understand, can become inconsistent if the same parameter chain is being passed from method to method • Divergent Change • symptom: one type of change requires changing one subset of methods; another type of change requires changing another subset • e.g., “I have to change these three methods every time I get a new database.” • Related to cohesion
  • 89. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 89 • Shotgun Surgery • a change requires lots of little changes in a lot of different classes • Feature Envy • a method requires lots of information from some other class • Move it closer! • Data Clumps • attributes that clump together (are used together) but are not part of the same class
  • 90. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 90
  • 91. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 91 • Lazy Class • A class that no longer “pays its way” • e.g., may be a class that was downsized by a previous refactoring, or represented planned functionality that did not pan out • Speculative Generality • “Oh, I think we need the ability to do this kind of thing someday” • thus have all sorts of hooks and special cases to handle things that aren’t required • Temporary Field • An attribute of an object is only set/used in certain circumstances; • but an object should need all of its attributes
  • 92. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 92 • Message Chains • a client asks an object for another object and then asks that object for another object etc. • client depends on the structure of the navigation • any change to the intermediate relationships requires a change to the client • Middle Man • If a class is delegating more than half its responsibilities to another class, do you really need it? Involves trade-offs, some design patterns encourage this (e.g., Decorator) • Inappropriate Intimacy • Pairs of classes that know too much about each other’s implementation details (loss of encapsulation)
  • 93. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 93 • Data Class (information holder) • These are classes that have fields, getting and setting methods for the fields, and nothing else; they are data holders, but objects should be about data AND behavior • Refused Bequest • A subclass ignores most of the functionality provided by its superclass • Subclass may not pass the “IS-A” test • Comments (!) • Comments are sometimes used to hide bad code • “…comments are often used as a deodorant”(!)
  • 94. 4/20/2020 S. Parsa, Associate Professor (www.parsa.iust.ac.ir) 94

Editor's Notes

  1. Consider that what you are planning for is – a week’s trip to visit few of your favorite destinations. And you got to plan for how you will be managing your accommodation, route, transportation, food and many more. You will want to have some travel agent to understand what you want and will take care about how to plan the trip. 
  2. Consider the case of a large-sized financial application. This application employs classes named CreateReport, CopyReport, DisplayReport, etc. to deal with its report generation functionality. Each class has exactly one method definition named create, copy, display, etc., respectively, and suffers from Imperative Abstraction smell. The data items relating to a report such as name of the report, data elements that need to be displayed in the report, kind of report, etc. are housed in a “data class” named Report.
  3. Consider the case of a large-sized financial application. This application employs classes named CreateReport, CopyReport, DisplayReport, etc. to deal with its report generation functionality. Each class has exactly one method definition named create, copy, display, etc., respectively, and suffers from Imperative Abstraction smell. The data items relating to a report such as name of the report, data elements that need to be displayed in the report, kind of report, etc. are housed in a “data class” named Report.
  4. Consider the case of a large-sized financial application. This application employs classes named CreateReport, CopyReport, DisplayReport, etc. to deal with its report generation functionality. Each class has exactly one method definition named create, copy, display, etc., respectively, and suffers from Imperative Abstraction smell. The data items relating to a report such as name of the report, data elements that need to be displayed in the report, kind of report, etc. are housed in a “data class” named Report.
  5. Consider the case of a large-sized financial application. This application employs classes named CreateReport, CopyReport, DisplayReport, etc. to deal with its report generation functionality. Each class has exactly one method definition named create, copy, display, etc., respectively, and suffers from Imperative Abstraction smell. The data items relating to a report such as name of the report, data elements that need to be displayed in the report, kind of report, etc. are housed in a “data class” named Report.
  6. • Long methods – These are undesirable because they affect the understandability and testability of the code. Long methods tend to do more than one piece of functionality, and they are therefore using many temporary variables and parameters, making them more error-prone. • Excessive branching – The intensive use of switch statements (or if–else–if) is in most cases a clear symptom of a non-objectoriented design, in which polymorphism is ignored.2 • Many variables used – The method uses many local variables but also many instance variables
  7. This example is paraphrased from a bug report on unused classes in JDK.4 The package sun.misc has classes that date back to early releases of JDK, and they were used by other classes in JDK internally. Later, many of the services provided by sun.misc package were provided as part of the public API. Eventually, the original clients of sun.misc package started using the services provided by the public API. Due to this, many of the original classes in sun.misc package became unreferenced abstractions. One such example is the internal class sun.misc.Service that was introduced in JDK 1.3, which was made redundant by the introduction of the class java.util. ServiceLoader in JDK version 1.6 (which is part of the public API). Hence, the original sun.misc.Service is an Unutilized Abstraction.
  8. In a large Java project that one of the authors was involved in, there was extensive use of concurrency. The code was developed using JDK 1.3 and contained several concurrent utilities such as a concurrent version of HashMap, a FIFO (First-In-First-Out) buffer that would block, and an array list implementation that used copy-on-write approach. When JDK 1.5 introduced java.util.concurrent package, developers started using the classes in this package without removing the original concurrent utilities which became Unutilized Abstractions.