<Design Patterns in Kotlin: Proxy and Decorator>
# feed
x

Design Patterns in Kotlin: Proxy and Decorator

Design pattern need not apply? Decorator/Proxy often introduce unnecessary wrapping and types
Copy code
val processor = LoginProcessor(
  Logger,
  CacheProcessor(
    Cache,
    RequestProcessor()
  )
)
We can achieve the same effect without introducing these wrappers/types by simply using extension functions
Copy code
val processor = Processor()
  .log(Logger)
  .cache(Cache)
👍 1
thoughts? @Alexey Soshin
a
Hi @xxfast, Using extension functions is a fine approach as well 🙂
x
The pattern really breaks down and we are just left with extension functions 😅 only remaining vestigial is the names decorator and proxy Anyways, great work with the video 👍 really made me rethink this whole pattern for my presentation
p
https://pl.kotl.in/t4R0DRmls same idea but with only interfaces and extensions
x
Funny how we both came to the same solution without the decorator pattern 😅
p
You could argue it’s still the decorate pattern, but without explicit types 😉
x
no wrapping though - which is good. This no longer resembles the original pattern from the GoF, therefore it is not decorator