Description

Incorrect or incomplete application of object-oriented programming principles can result in issues that damage system functionality and performance.

All such issues are called Object-Oriented Abusers.

Here is a list of such observations.

  • Alternative Classes with Different Interfaces
  • Switch Statements
  • Temporary Field
  • Refused Bequest

Alternative Classes with Different Interfaces

Problem: Two classes perform identical functions but have different method names.

Solution: Use the mentioned refactoring techniques to avoid these kinds of code smells.

  • Rename Method
  • Move Method
  • Add Parameter
  • Parameterize Method
  • Extract Superclass

Switch Statements

Problem: You have a complex switch operator or sequence of if statements.

Solution: Use the mentioned refactoring techniques to avoid these kinds of code smells.

  • Extract Method
  • Move Method
  • Replace Type Code with Subclasses
  • Replace Type Code with State/Strategy
  • Replace Conditional with Polymorphism
  • Replace Parameter with Explicit Methods
  • Introduce Null Object

Temporary Field

Problem: Temporary fields get their values (and thus are needed by objects) only under certain circumstances. Outside of these circumstances, they’re empty.

Solution: Use the mentioned refactoring techniques to avoid these kinds of code smells.

  • Extract Class
  • Replace Method with Method Object
  • Introduce Null Object

Refused Bequest

Problem: If a subclass uses only some of the methods and properties inherited from its parents, the hierarchy is off-kilter. The unneeded methods may simply go unused or be redefined and give off exceptions.

Solution: Use the mentioned refactoring techniques to avoid these kinds of code smells.

  • Replace Inheritance with Delegation
  • Extract Superclass

Overall

We now know how to find and resolve object-oriented abusers in the code to improve the code quality.

Related Links