Skip to content

Latest commit

 

History

History
105 lines (60 loc) · 3.97 KB

File metadata and controls

105 lines (60 loc) · 3.97 KB

Code Smell 25 - Pattern Abusers

Code Smell 25 - Pattern Abusers

Patterns are awesome. With great powers comes great responsibility.

TL;DR: Don't abuse patterns.

Problems

  • Over design

  • Readability

Solutions

  1. Measure the tradeoff of patterns usage.

  2. Create solutions based on real-world names (essential) over architecture (accidental).

  3. Choose good names.

  4. User MAPPER technique to find bijection real entities.

Sample Code

Wrong

public final class FileTreeComposite {
    // name should be inferred from behavior
}
    
public final class DateTimeConverterAdapterSingleton { }
public final class PermutationSorterStrategy { } 
public final class NetworkPacketObserver { }    
public final class AccountsComposite { }

Right

public final class FileSystem {
    // These names map 1:1 to real-world concepts
}

public final class DateTimeFormatter { }
public final class BubbleSort { }
public final class NetworkSniffer { }
public final class Portfolio { }

Detection

It would be very difficult to create automatic detection rules.

A class name with more than one pattern on it, is a warning.

Tags

  • Abuser

  • Naming

Conclusion

Chose when to apply a pattern solution. You are not smarter for using too many patterns. You are smart if you choose the right opportunity for everyone.

Relations

Code Smell 06 - Too Clever Programmer

Singleton - The root of all evil

Code Smell 38 - Abstract Names

Code Smell 47 - Diagrams

Code Smell 32 - Singletons

More Info

How to Decouple a Legacy System

What exactly is a name - Part II Rehab

Credits

Photo by Nathan Dumlao on Unsplash


When you have a hammer, every problem looks like a nail.

Software Engineering Great Quotes


This article is part of the CodeSmell Series.

How to Find the Stinky Parts of your Code