# 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](https://maximilianocontieri.com/no-silver-bullet)) over architecture (accidental).

3. Choose [good names](https://maximilianocontieri.com/what-exactly-is-a-name-part-ii-rehab).

4. User [MAPPER](https://maximilianocontieri.com/what-is-wrong-with-software) technique to find [bijection](https://maximilianocontieri.com/the-one-and-only-software-design-principle) real entities.

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/a94aac5dd5fee1e1c19b4b07e87e7887)
```java
public final class FileTreeComposite {
    //name should be inferred from behaviour
}
    
public final class DateTimeConverterAdapterSingleton {
    //
}

public final class PermutationSorterStrategy {
    //
} 

public final class NetworkPacketObserver {
    //
}
    
public final class AccountsComposite {
    //
}
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/9adec62e0637199e351100eb2ece56f2)
```java
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](https://maximilianocontieri.com/code-smell-06-too-clever-programmer) for using too many patterns. You are smart if you choose the right opportunity for everyone.

# Relations

%[https://maximilianocontieri.com/code-smell-06-too-clever-programmer]

%[https://maximilianocontieri.com/singleton-the-root-of-all-evil]

# More Info

%[https://maximilianocontieri.com/how-to-decouple-a-legacy-system]

%[https://maximilianocontieri.com/what-exactly-is-a-name-part-ii-rehab]

# Credits

Photo by <a href="https://unsplash.com/@nate_dumlao">Nathan Dumlao</a> on <a href="https://unsplash.com/s/photos/addict">Unsplash</a>

* * *

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

%[https://maximilianocontieri.com/software-engineering-great-quotes]

* * *

This article is part of the CodeSmell Series.

%[https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code]

*Last update: 2021/07/09*
