DEV Community

Yonatan Karp-Rudin
Yonatan Karp-Rudin

Posted on • Originally published at yonatankarp.com on

Kotlin Code Smell 017 - Pattern Abusers

Problems

  • Over Design

  • Readability

Solutions

  1. Measure the tradeoff of pattern usage.

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

  3. Choose good names.

  4. Use the MAPPER technique to find bijection real entities.

Sample Code

Wrong

class FileTreeComposite {
    // name should be inferred from behavior
}

class DateTimeConverterAdapterSingleton {
    // ...
}

class PermutationSorterStrategy {
    // ...
}

class NetworkPacketObserver {
    // ...
}

class AccountsComposite {
    // ...
}

Enter fullscreen mode Exit fullscreen mode

Right

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

class DateTimeFormatter {
    // ...
}

class BubbleSort {
    // ...
}

class NetworkSniffer {
    // ...
}

class Portfolio {
    // ...
}

Enter fullscreen mode Exit fullscreen mode

Conclusion

Choose when to apply a pattern solution. You are not being smarter by using too many patterns. You are smart if you choose the right opportunity to use the patterns.


Stay updated with my latest thoughts and ideas by registering for my newsletter. Connect with me on LinkedIn or Twitter. Let's stay connected and keep the conversation going!


Credits

Top comments (0)