Inspired by https://github.com/mariofusco/from-gof-to-lambda
Blog posts:
- Part 1: https://dev.to/lovis/gang-of-four-patterns-in-kotlin
- Part 2: https://dev.to/lovis/gang-of-four-patterns-in-kotlin---slight-return
Watch me talk about it: https://youtu.be/xxGCVVtMVn4 (2018 @code.talks hamburg)
| Pattern | Kotlin |
|---|---|
| Builder | apply function / named constructor parameters |
| Decorator | Extension Functions / function composition |
| Interpreter | sealed classes |
| Iterator | operator functions |
| Observer | observable delegate |
| Prototype | Data class |
| Singleton | object declaration |
| Strategy | functions |
| Template Method | (top-level) functions |
| Visitor | Pattern Matching / when |
ℹ️ If you import the project into intelliJ, make sure to uncheck "Create separate module per source set"!