Kotlin Code Smell 17 - Pattern Abusers
Beyond Buzzwords: The Art of Thoughtful Pattern Application
Play this article
Table of contents
Problems
Over Design
Readability
Solutions
Measure the tradeoff of pattern usage.
Create solutions based on real-world names (essential) over accidental architecture.
Choose good names.
Sample Code
Wrong
class FileTreeComposite {
// name should be inferred from behavior
}
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
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.