Yonatan Karp-Rudin
Yonatan Karp-Rudin

Follow

Yonatan Karp-Rudin

Follow
Kotlin Code Smell 017 - Pattern Abusers

Kotlin Code Smell 017 - Pattern Abusers

Patterns are awesome, but with great powers comes great responsibility.

Yonatan Karp-Rudin's photo
Yonatan Karp-Rudin
·Mar 11, 2023·

1 min read

Play this article

Table of contents

  • Problems
  • Solutions
  • Sample Code
  • Conclusion
  • Credits

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

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

class DateTimeConverterAdapterSingleton {
    // ...
}

class PermutationSorterStrategy {
    // ...
}

class NetworkPacketObserver {
    // ...
}

class AccountsComposite {
    // ...
}

Right

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

class DateTimeFormatter {
    // ...
}

class BubbleSort {
    // ...
}

class NetworkSniffer {
    // ...
}

class Portfolio {
    // ...
}

Conclusion

Chose 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.

Credits

 
Share this