Design Patterns in Kotlin Episode #2 | Kotlin Tutorial

  Рет қаралды 20,156

Kotlin by JetBrains

Kotlin by JetBrains

Күн бұрын

Пікірлер: 56
@rodneymkay
@rodneymkay 2 жыл бұрын
Not a big deal, but there's a small bit of audio missing at the 16 Minute mark :)
@Poisonedyouth79
@Poisonedyouth79 2 жыл бұрын
Love this series ❤️
@jolly_joker
@jolly_joker 2 жыл бұрын
Love it, hope to see more of this!
@ArthurKhazbs
@ArthurKhazbs 4 ай бұрын
Actually interesting to know: What parts of the book did you bookmark? I think sharing your tabs can be a fun thing to do and it would also help promote the book!
@RatkaOdalovic-Radusinovic
@RatkaOdalovic-Radusinovic Жыл бұрын
@19:12 wanted to probably say the reverse. You converted proxy to decorator. Great video 🎉
@zhoon-kim
@zhoon-kim 2 жыл бұрын
유익한 내용 감사합니다. 구현하면서 생각을 따라가게 되어서 정말 좋았네요. 마지막 내용을 보니 책으로 한 번 보고 다시 또 보면 더 좋을 것 같네요
@bboydarknesz
@bboydarknesz 2 жыл бұрын
thanks! this is cool series, with live code and more real implementation example
@dibyaranjanmishra4272
@dibyaranjanmishra4272 2 жыл бұрын
Great explanation
@Kotlin
@Kotlin 2 жыл бұрын
Glad it was helpful!
@hj2931
@hj2931 2 жыл бұрын
nice video and nice book, thanks for sharing!
@ramkumarkb
@ramkumarkb 2 жыл бұрын
Great series 😍
@scottloewke5199
@scottloewke5199 Жыл бұрын
Decorator is a good example of OCP: open for extension, closed for modification. Looking forward to reading this book. The Head First Design Patterns book has a good chapter that covers Decorator, although it's in Java.
@t54f
@t54f 2 жыл бұрын
Great example 💯
@sarpedonmontecarlo8397
@sarpedonmontecarlo8397 2 жыл бұрын
Very interesting lesseon, Also enjoyed the educational atmosphere of you guys interacting with the code. Cheers!
@LA-fb9bf
@LA-fb9bf 2 жыл бұрын
Very good! I like this deep dive!
@gorttar
@gorttar 2 жыл бұрын
Great video but there is more fundamental difference between proxy and decorator than described in video: Proxy is intended to provide a surrogate or placeholder for another object to control access to it Decorator is intended to add some functionality for another object without controlling access to it According to this, there is a difference in implementation: proxy controls creation of delegate (creates by itself or obtains from dependency injection container) while constructor of decorator takes delegate as a parameter. So both LoggingProcessor and CachingProcessor are actually deocrators rather than proxies.
@kyay10
@kyay10 2 жыл бұрын
Isn't CacheProcessor "controlling access" to the underlying processor by not calling it sometimes?
@gorttar
@gorttar 2 жыл бұрын
@@kyay10 no because you've access to underlying one from caller side: caller passes an instance of underlying processor to CacheProcessor constructor. Compare to Spring beans for example: all Spring injections you have in your bean are actually proxies and caller side never directly instantiate beans. In short: proxy tries to completely substitute and hide wrapped object while decorator is just another object with additional functionality.
@laujimmy9282
@laujimmy9282 2 жыл бұрын
Great series, now I have a better idea on how we can use proxy and decorator
@robchr
@robchr 2 жыл бұрын
Now for the functional version! A processor is just a `(Request) -> Response` function and decorating is just map chaining functions.
@markonovakovic3838
@markonovakovic3838 2 жыл бұрын
maybe fun interface Processor : (Request) -> Response would work better for most cases, you keep polymorphism and you get that functional look and feel
@donwald3436
@donwald3436 2 жыл бұрын
Now explain why a monad is like a burrito.
@ArthurKhazbs
@ArthurKhazbs 4 ай бұрын
@@markonovakovic3838 Oh yes, fun interface really is the fun part of Kotlin
@TheMassif
@TheMassif 2 жыл бұрын
Great working example, love it ❤
@Никита-т5щ7ф
@Никита-т5щ7ф 2 жыл бұрын
That's helpful, thanks!
@markonovakovic3838
@markonovakovic3838 2 жыл бұрын
great video, would love to see more episodes from this series and maybe some functional refactoring
@mayikx
@mayikx Ай бұрын
Do you have a Playlist about it?
@chrismuga
@chrismuga 2 жыл бұрын
This is simply. Awesome
@xetra1155
@xetra1155 2 жыл бұрын
So can we say that the Filter "Pattern" or at least how FilterChains are implemented is somewhat a mix of Proxy and Decorator? Because in a Filter there is a condition that decides if the next in line will be process/called?
@hamzaproho6423
@hamzaproho6423 2 жыл бұрын
Thank you so much buddy i digg whole youtube for this but you are the only one ❤️🔥
@amol_
@amol_ 2 жыл бұрын
I implemented similar kind of pattern for Kafka consumer processing event, We had requirement where we need to check in inbox table for eventId before processing the event basically for duplicate check so what i did i created HOF and wrapped processEvent function in that. I hope Kotlin will have pattern matching like OCaml that this language will be rock :)
@Quillraven
@Quillraven 2 жыл бұрын
Out of interest: the caching can be a simple one liner,no? return cache.getOrPut(request) { processor.process(request) }
@kyay10
@kyay10 2 жыл бұрын
Yep, or Seb could've used cache.get(request) ?: processor.process(request).also { cache.put(request, it) }
@jakubgwozdz2780
@jakubgwozdz2780 2 жыл бұрын
yes I was surprised Sebastian didn't use it, but I guess it's better to focus on just one thing in the video and leave such flavours for other occasion.
@ArthurKhazbs
@ArthurKhazbs 4 ай бұрын
There were quite a few lines of code that could be simplified, but that was out of scope for the video
@ehsan13671
@ehsan13671 2 жыл бұрын
great examples. thanks!
@jakubgwozdz2780
@jakubgwozdz2780 2 жыл бұрын
sometimes when people have problems figuring out what the decorator pattern is about, I tell them: "think about BufferedInputStream" and they are like "oh yes of course" :) (because indeed, a proxy and a decorator are so similar there's a little point to differentiate between them)
@PedroBarbosaRoman
@PedroBarbosaRoman 2 жыл бұрын
Would you say that Kotlin Flow and it's processing/transformation functions are a kind of a Wrapper pattern for a Type that is already implemented but for reactive programming?
@camilocepedadanies
@camilocepedadanies 2 жыл бұрын
very much your efforts to help us noobs out.
@_caioiglesias_
@_caioiglesias_ 2 жыл бұрын
Packtpub redirects print purchases to Amazon ☹️
@IsuruKusumal
@IsuruKusumal 2 жыл бұрын
Decorator/Proxy often introduce a lost of unnecessary wrappings - we can achieve the same effect without introducing these wrappers/types by simply using extension functions
@FuNIpoxi
@FuNIpoxi 2 жыл бұрын
Well not really I think, since the Decorator/Proxy allow to isolate the addon-behavior from the base type/interface. It means that this will allow you to compose concretions at your will later, depending on the usecase. The extension methods, on the other hand, will modify the behavior of the base type/interface for your whole project... so you can forget about composing behaviors together. Extension methods are cool, but I don't think they fit the need exposed in this video
@IsuruKusumal
@IsuruKusumal 2 жыл бұрын
@@FuNIpoxi They defintely fit the need. I've written up the same solution with just extension methods. No need for a pattern, wrappers, types or nesting
@IsuruKusumal
@IsuruKusumal 2 жыл бұрын
my gh tag is xxfast
@jakubgwozdz2780
@jakubgwozdz2780 2 жыл бұрын
Extension functions can solve *some* off these needs too, but they are not design patterns. They are cool language flavors but under the hood they are just static utility functions. And it's a bit harder to properly compose them in a way presented in this wideo, especially sometimes desired non-associativity, when caching(logging(processor)) != logging(caching(processor))
@IsuruKusumal
@IsuruKusumal 2 жыл бұрын
@@jakubgwozdz2780 in my implement above, I've composed this as a simple list of call chains Processor().log().cache() != Processor().cache().log() It is far more elegant to properly compose than to nest everything in object My point is that you don't need this design pattern
@scienceschool4998
@scienceschool4998 2 жыл бұрын
How I wish I can write code they way you people do
@GulshanurRahman
@GulshanurRahman 2 жыл бұрын
I think this should be called "middleware pattern"?
@veygard
@veygard 2 жыл бұрын
ty for video
@muhammednuriozturk02
@muhammednuriozturk02 2 жыл бұрын
works gj
@bahtiyaryudis6333
@bahtiyaryudis6333 2 жыл бұрын
Ok
@TobiasKerst
@TobiasKerst 2 жыл бұрын
way too many cuts in between sentences. Kills the video's flow and made me quit after the first few minutes.
@donwald3436
@donwald3436 2 жыл бұрын
It shouldn't be called Decorator or Wrapper, it should be called an around advice. Only half joking.
@ThinkTablet
@ThinkTablet 2 жыл бұрын
Thanks Folks, What if we change it so that caller could build it like this? newRequestProcessor() .decorateWithCache() .decorateWithLogging() is that confusing?
@jakubgwozdz2780
@jakubgwozdz2780 2 жыл бұрын
drop the "new" and "decorate" and it's clear and readable :)
@donwald3436
@donwald3436 2 жыл бұрын
I like that, like a builder. I guess each new decorator add an extension function to Processor? I'd prefer RequestProcessor().with(logger).with(cache) that delegates to the decorator constructors in a generic way... but no immediate ideas on how to make that happen.
Kotlin Design Patterns and Best Practices | Talking Kotlin
40:40
Kotlin by JetBrains
Рет қаралды 27 М.
Factory Design Pattern in Kotlin
25:25
Kotlin by JetBrains
Рет қаралды 27 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 903 М.
Context Receivers Are Coming to Kotlin!
31:44
Kotlin by JetBrains
Рет қаралды 38 М.
Diving into advanced Kotlin features by Simon Wirtz
49:37
Devoxx
Рет қаралды 23 М.
What's new in Kotlin for Android
12:22
Android Developers
Рет қаралды 27 М.
NEW OPERATOR in Kotlin (and true open-ended ranges)
13:47
Kotlin by JetBrains
Рет қаралды 19 М.
Design Patterns: Strategy
13:59
Microsoft Visual Studio
Рет қаралды 38 М.
Applying the Builder Pattern in Kotlin
10:27
Dave Leeds
Рет қаралды 5 М.
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН