Code Smells Flashcards
Signs and indicators of future problems/issues in the source code. May cause the program to be hard to understand, maintain and extend.
Code Smells
Object-Orientation Abusers:
- method or class is trying to exhibit too many behaviors
Too Many Switch Statements
Object-Orientation Abusers:
- fields get their values only under certain circumstances, outside of these circumstances, they’re empty
- refers to a field (variable) that is used only in certain situations or temporarily during execution
Temporary Field
Object-Orientation Abusers:
- occurs when a subclass inherits from a parent class but does not use all of the methods and properties of the parent class
- when subclass does not use members inherited from a superclass
Refused Bequest
Object-Orientation Abusers:
- closely related classes should share the same interface, so they can be pluggable
- two classes perform identical functions but have different method names
Alternative Classes with Different Interfaces
Bloaters:
- a method contains too many lines of code
- methods that are too long are difficult to understand, test, and maintain
Long Method
Bloaters:
- a class that contains many fields/methods/lines of code
- classes that are too large are difficult to understand, test, and maintain
Large Class
Bloaters:
- occurs when developers overuse primitive data types, such as integers, strings, and booleans, to represent complex domain concepts
- Using primitive instead of creating own classes
Primitive Obsession
Bloaters:
- more than three or four parameters for a method
- methods have too many parameters
Long Parameter List
Bloaters:
- a group of data that always appear together
- occurs when a group of related variables are passed around together in a clump throughout various parts of the program
Data Clumps
Change Preventers:
- same class changed for different reasons
- having to change many unrelated methods when you make changes to a class
Divergent Change
Change Preventers:
- Several classes changed for every new feature/code
- making any modifications requires that you make many small changes to many different classes
Shotgun Surgery
Change Preventers:
- occurs when an inheritance tree depends on another inheritance tree by composition
Parallel Inheritance Hierarchies
Change Preventers:
- code that is too difficult to change without breaking other parts of the codebase. This can make the code difficult to maintain and extend
Rigid Code
Dispensables:
- occurs when a method is filled with explanatory comments
Unnecessary Comments
Dispensables:
- is code that appears in multiple places in the codebase
- when the same code is repeated multiple times in different parts of the application
Duplicate Code
Dispensables:
- occurs when a class is rarely used or has very little functionality
- when a class doesn’t do much
Lazy Class
Dispensables:
- occurs when a class is defined primarily to hold data and lacks significant behavior or functionality
- these are simply containers for data used by other classes.
Data Class
Dispensables:
- Unused code
- a variable, parameter, field, method or class is no longer used (usually because it’s obsolete)
Dead Code
Dispensables:
- occurs when code is written to anticipate future needs that may not actually materialize
Speculative generality
Couplers:
- a method accesses the data of another object more than its own data
- when a method excessively accesses the data of another class
Feature Envy
Couplers:
- when two classes are constantly accessing each other’s members
Inappropriate Intimacy
Couplers:
- occurs when the program asks an object to get another object
- occurs when a class needs to call multiple methods on other classes to get to a particular piece of data or functionality
Message Chains
Couplers:
- occurs when a class or an object primarily delegates its work to other classes or objects, forwarding messages without adding any meaningful value of its own
Middle Man