Null Object Pattern - Design Patterns (ep 18)

Поделиться
HTML-код
  • Опубликовано: 7 фев 2025
  • Video series on Design Patterns for Object Oriented Languages. This time we look at the Null Object Pattern.
    💙 BUY MY BOOK:
    leanpub.com/th...
    ► The playlist
    • Design Patterns in Obj...
    📘 Head First: Design Patterns
    geni.us/nlbA6
    📘 Design Patterns: Elements of Reusable Object-Oriented Software
    geni.us/PsXmo
    ► Sandi Metz - Nothing is Something
    • RailsConf 2015 - Nothi...
    💪 Patreon Community
    / christopherokhravi
    📚 Products I Recommend
    geni.us/71ZXF

Комментарии • 180

  • @sayantansengupta9939
    @sayantansengupta9939 4 года назад +13

    It is sad that you stopped this series. Watched all your videos last year and really loved all of them. Coming back in 2021 with the hope that you may have uploaded new videos.

  • @renatoinnocenti
    @renatoinnocenti 6 лет назад +135

    Continue this series please!

    • @ChristopherOkhravi
      @ChristopherOkhravi  6 лет назад +29

      If all goes well I’ll start dropping episodes again within a month :) Thank you for the patience :) :) And your enthusiasm :)

    • @takssir
      @takssir 6 лет назад +3

      @@ChristopherOkhravi hi, do you have any new?

    • @samueljames7071
      @samueljames7071 6 лет назад +10

      @@ChristopherOkhravi yes please can you cover the MVC pattern!

    • @fadybichara
      @fadybichara 6 лет назад +1

      Hey Chris .. this is very helpful .. I Wish you can continue this amazing series

    • @victorbrylew1775
      @victorbrylew1775 5 лет назад +17

      Next episode of this series is NoEpisode. Just handle it correctly!

  • @piyushajmani5
    @piyushajmani5 5 лет назад +41

    Where'd you go? I miss you so.
    Please continue the series.

  • @professorfontanez
    @professorfontanez 4 года назад +17

    The first time I heard of this pattern, I dismissed it immediately as dumb. Then I took the time to examine it and it literally changed my life. It is now my favorite pattern. The simplicity is genius and it makes your code some much better and cleaner.
    I recently implemented (within the last year or so) a small framework where I received models from an XML file as (JAXB) objects. I replaced nulls with Null Objects to avoid situations such as the wrong name or ID is pass and a valid model could not be found. So instead, my framework simply returns a null object and the system would not break because my null object obviously respects the interface.
    Fast forward to about a month ago. I needed to integrate this framework to interact with a legacy system that doesn't generate these models. I was able to seamlessly do it because, now my null object is used to represent the "model" of the legacy system. In order words, the legacy system has NO MODEL; which is precisely what the null object represents. This is why this changed my life. That decision around 12 months ago to put this concept in practice, even though I "didn't needed it" saved me weeks or perhaps months of additional implementation. I was able to integrate this legacy system in a couple of days.

    • @ChristopherOkhravi
      @ChristopherOkhravi  4 года назад +3

      The excellent and vivid examples that you’re scattering over the comment sections truly improve the value of this RUclips channel so let me just pause and say: thank you! Great examples 😊😊

    • @professorfontanez
      @professorfontanez 4 года назад +3

      @@ChristopherOkhravi Thank you Chris. I am actually about to sit down and write about this pattern in my blog and am going to refer to this video. And trust me, it is no exaggeration when I said that it changed my life (professionally speaking of course). And one thing I didn't mention is that I wasn't the one who did the integration. Someone else on the team did. All I had to do was explain the concept in one single sentence. Two days later, integration was done.

    • @ChristopherOkhravi
      @ChristopherOkhravi  4 года назад +1

      @@professorfontanez If you wish, please feel free to post the blog link as a comment here when it's done. In case it gets caught in the spam filter, let me know.

  • @claudios
    @claudios 7 лет назад +28

    This is awkward, I didn't get you anything for Christmas... and here you got me just what I asked for.
    Thank you!

  • @omarabdo6403
    @omarabdo6403 4 года назад +1

    What a great journey! I am ETERNALLY grateful! a few weeks ago, when I started this serious I didn't know anything about design patterns but now I've already implemented many of them to my projects and I can feel the huge enhancement of technical excellency that was introduced to me and to my projects in such a short period of time. it was a shock to see this amazing serious ends although there are other patterns to be covered. I really hope you would resume this playlist even though it has been 2 years since this video. much much love and many thanks to you Christopher!

  • @Brudof
    @Brudof 3 года назад +4

    Loved these videos. I learn much better in this format vs reading on my own. Hope to see you continue this series one day.

  • @dennimer
    @dennimer 2 года назад +1

    Thank you so much Christopher! I hope you will have time and energy to continue this series. It's hard to find even a payed content with such amazing quality!

  • @ZaneSelvans
    @ZaneSelvans 4 года назад +2

    This was a really valuable and thoughtful series! I tried to read the Gang of Four book initially and was overwhelmed, but with this as background it's much more accessible. You're a good teacher, I hope you can find the time to return to making videos in the future!

  • @shraddheshbhandari8740
    @shraddheshbhandari8740 6 лет назад +4

    The composite pattern NullIterator example was really good and a perfect use case. On another side note, the youtube "Skip Ad" button before a video starts playing can be another good example (that was motivated by your NullCommand discussion). This button can be disabled for like 5 seconds during which the ad cannot be skipped and thus can be represented by the NullCommand concretion during that time interval and then change its state use the SkipCommand concretion.

    • @ChristopherOkhravi
      @ChristopherOkhravi  6 лет назад

      Wow! Excellent example! I hadn’t thought of that :) :) Thanks for sharing :)

  • @valkon_
    @valkon_ 3 года назад

    You captivated me from the beginning, I could listen you for hours.

  • @alexhelkar
    @alexhelkar 5 лет назад +1

    Very talented author and a great playlist! Came across these videos and can’t stop watching. Thank you so much for what you’ve already done. Please continue!

  • @grayboywilliams
    @grayboywilliams 4 года назад

    Thank you so much for this series! It was so helpful. You are still maybe the only person who put in this much work into explaining these patterns and I appreciate that so much.

  • @vperaltac
    @vperaltac 6 лет назад +8

    Excellent series, I had to learn a lot of patterns in a month and you helped me a freaking lot, this is hands down the best resource on the internet for design patterns.
    PD : You mentioned the two books so much over the series that now when i see the titles I subconsciously read it with your voice lol.
    Thank you very much Christopher.

    • @ChristopherOkhravi
      @ChristopherOkhravi  6 лет назад +2

      Hahahha that is awesome. Serious brain washing :) :) Thank you for watching and I’m glad it was useful :)

  • @SbeveAmogus
    @SbeveAmogus 7 лет назад +1

    Happy to see how your channel gets more and more subscribers. When I checked the last time it was 10k, now it’s 13k. We need videos like this

  • @bragoen
    @bragoen 6 лет назад

    This pattern is so difficult to make people accept, but it's helped me my whole life. Stumbled upon your playlist this weekend and I think you're doing a great job, I can now point the juniors where I work to your content. After looking it it I also want to give it a try myself for french speakers.

  • @akshayvenkatesh5372
    @akshayvenkatesh5372 7 лет назад +18

    Great stuff! Please please make a video on Visitor pattern.

  • @TheToeFungi
    @TheToeFungi 5 лет назад +12

    What might be quite cool is a git repository with an example of an implementation of the design pattern being explained.

    • @cliid4355
      @cliid4355 4 года назад +6

      Actually, I made one. github.com/cliid/design_pattern has all of the design patterns mentioned by Chris, and also some cool ones like Memento Pattern, and so forth.

  • @meduto9584
    @meduto9584 4 года назад +1

    Please continue Christopher ! This series was amazing !

  • @BlockDemos
    @BlockDemos 2 года назад

    I just finished this series, thank you very much, Christopher.

  • @krozaine
    @krozaine 5 лет назад +1

    This is a great series and I have thoroughly learnt a lot! Your presentation is very natural and instinctive to understand. If your ever get time, we would be glad to have more videos on design patterns. There are a few patterns left on sourcemaking.com that weren't covered here. Appreciate your efforts. Thanks a lot!!

  • @txxie
    @txxie 6 лет назад +1

    I really like your videos about design patterns. Continue this series, please!!!

  • @kalahari8295
    @kalahari8295 2 года назад

    Still the best series ever. Continue 😭

  • @suhastm6696
    @suhastm6696 3 года назад

    Thanks for the wonderful series. I have learnt a lot from this design pattern series. Thank you Christopher.

  • @amitrk23
    @amitrk23 5 лет назад

    Thanks a ton for all the videos in this series.
    Understood different design patterns.
    Great teaching :)

  • @SrishtiShukla9911
    @SrishtiShukla9911 5 лет назад

    Hi @Christopher Okhravi your videos are great.. Kindly continue this series...

  • @martinleeuwangh
    @martinleeuwangh 7 лет назад

    Thanks, Chris, for another great video. Happy birthday for last week, merry Christmas and a happy new year, too!

  • @jeronimocarrizo5855
    @jeronimocarrizo5855 5 лет назад +1

    Thank you so much Chris for this amazing video. I love you work! please keep doing that kind of video! I really love it! Thank you so much again!!!!

  • @plamengeorgiev1388
    @plamengeorgiev1388 3 года назад

    Excellent DP for cases where you can replace IFs or other conditions,
    with SOMETHING that does NOTHING.

  • @AndrewReeman_RemD
    @AndrewReeman_RemD 7 лет назад +1

    Your videos are great! Excellent examples :) Thanks for these. A video on the visitor or flux pattern would be awesome!

  • @MrAceman82
    @MrAceman82 3 года назад

    Both are books are great. However, I have enjoyed the video. It is very refreshing to reminder of useful patterns

  • @guyr989
    @guyr989 5 лет назад +5

    Will you continue with your videos?
    If it's about the views I can watch them a million times.

  • @konzinovmaverick4539
    @konzinovmaverick4539 7 лет назад +1

    Great one dude. This made my christmas

  • @kclee8998
    @kclee8998 5 лет назад +1

    Thank you very much for this series.

  • @seanbuckmaster
    @seanbuckmaster 2 года назад

    Thanks for the series. It was great. Please do more.

  • @ColorBaII
    @ColorBaII 5 лет назад

    I like this video much. Good job. I completely dived into the topic.

  • @reyazahmed9320
    @reyazahmed9320 6 лет назад +1

    Hey Christopher, thanks for your awesome work. Please make a video on the visitor pattern.

  • @TheMinino123
    @TheMinino123 6 лет назад +1

    Thank you so much for all this work. Really appreciated.

    • @ChristopherOkhravi
      @ChristopherOkhravi  6 лет назад +1

      And thank you for watching :) And for commenting. I’m glad to hear that the content is useful :) Best of luck with your endeavors!

  • @StevenMartinGuitar
    @StevenMartinGuitar 4 года назад

    Plenty more design patterns to cover 😂 loved these videos and want to see more!

  • @Cempa666
    @Cempa666 4 года назад

    Loved all videos so far, any ETA on the next couple of videos, can't get enough :)

  • @oscardiaz9170
    @oscardiaz9170 4 года назад

    I understand polimorfism now thanks to your animal example... thank you!

  • @panosgr7228
    @panosgr7228 3 года назад

    Please continue this amazing series! Maybe explain the patterns from "Design Patterns: Elements of reusable Object-oriented software"?

  • @stanislavspatari2960
    @stanislavspatari2960 6 лет назад

    Great stuff, hope you'll make more series on this topic.

  • @gleisonsubzeroKZ
    @gleisonsubzeroKZ 4 года назад

    this series has to continue.

  • @diegocuencaramos8038
    @diegocuencaramos8038 3 года назад

    Please more of this, is awesome!!

  • @igormiholic2817
    @igormiholic2817 7 лет назад

    i really like your code walks. they're great, short and on point. these are just too long, at least for me.

  • @Lahiru_Udana
    @Lahiru_Udana 6 лет назад

    Thank you for this great series

  • @armenchik_dzhan
    @armenchik_dzhan 3 года назад

    this is amazing thank you for this playlist!

  • @manishjangra4332
    @manishjangra4332 7 лет назад

    hey chris...thanks for these videos on design patterns..you are really a good explainer. you make everything simple...Can you please make videos on patterns where you practically implement these patterns.?? It will be very good if you make coding examples of these patterns..thanks in advance.. Rock on

  • @sketchupgoo3683
    @sketchupgoo3683 7 лет назад

    Hola Christopher! Te saludo desde Perú, la verdad no se si sepas español xD asi que traduciré lo que quería decirte... congratulations! I always view your videos before my classes of Computer Science in my university, and believe me. I understand every word you say Keep in that way! you are doing great! My english is not very good, so don't be rude with me with my comment! Happy New Year! and thanks a lot!

  • @hdanijel
    @hdanijel 6 лет назад

    again . . .beautiful!
    love your work!
    Would you consider making videos about stacks that you mention, with pop push and pointers (code included :P like always)
    also queues, linked lists and others . . .also algorithms like sorting and . . .you know.
    I love this playlist. LOVE it!

  • @snigdhav7068
    @snigdhav7068 6 лет назад

    Thank you so much Christopher for these videos!

  • @jesuscruzhernandez8439
    @jesuscruzhernandez8439 2 года назад +1

    #Continue this series please!

  • @Денис-ж3ф5р
    @Денис-ж3ф5р 3 года назад

    Damn it's soooo easy and extremely genius!!!!!

  • @belugaaa6649
    @belugaaa6649 4 года назад

    Hey Christopher okhravi, please finish these series :)

  • @asheshsen1
    @asheshsen1 6 лет назад

    Great content and if not the best, one of the best youtube videos on explaining design patterns and explaining the rationale behind it. I was wondering if you could also do videos on Refactoring. Martin Fowler's "Refactoring" book could be one option, when you have free time. Just a suggestion. Feel free to ignore. I don't mean to put any pressure or demand. Great work. Glad I found your channel and appreciate it :)

  • @matiascasag
    @matiascasag 6 лет назад +1

    Thanks for all the videos! Can you make a video on builder pattern?

  • @harvanharvan
    @harvanharvan 7 лет назад

    Thank you super much. Great video.

  • @daniellive590
    @daniellive590 4 года назад

    7:30: Supplyimplementation within no animal for all methods requried by the interface of animal

  • @sneha7130
    @sneha7130 6 лет назад +7

    Hey! Can you make a video on builder pattern?

  • @angelrodriguez2259
    @angelrodriguez2259 5 лет назад

    Replacing conditionals with polymorphism? Sounds so cool that I must try!

  • @nisevi
    @nisevi 7 лет назад

    Hi there!! Thank you for this awesome collection of videos about design patterns :) !! One thing, it would be to much to ask if you could sort the collection for starting with the latest updated first?, please. That way I don't have to scroll all the way down when I want to keep watching your videos :).

  • @ShobiPPpro
    @ShobiPPpro 7 лет назад

    Superb Videos.... Keep Inspiring

  • @bsuperbrain
    @bsuperbrain 7 лет назад

    Please make video about the visitor pattern, make comparison builder vs. factory! So many interesting things have remained. :)

  • @gustavomesel1637
    @gustavomesel1637 6 лет назад

    First of all, I gotta say your videos are amazing. I think these are the best explanations about design patterns that I have ever encountered! Awesome work.
    Now, about the Null Object Pattern, I have a question. You mention that one use of this pattern is to avoid having to check for null at every method (using polymorphism to replace conditionals), but I don't think that this will actually prevent the null checking. If you have a method that takes an Animal a (like in your example) and then you do "return a.speak()", even if there is such a thing as a "NoAnimal" subclass, it would still be possible to send null to that method, and you'd still have to do the checking (since, in some languages like c++, using null can actually crash the program). So the NoAnimal doesn't actually prevent you from doing all the null returns.

  • @piotrjaga6929
    @piotrjaga6929 2 года назад

    Thank you!

  • @VisualBRON
    @VisualBRON 6 лет назад +5

    Are you going to finish the Design Pattern videos?

  • @Hassanlou
    @Hassanlou 2 года назад

    @chris, do you have any plans to continue this series? BTW thanks for all your sharing knowledge not only DP but also others like SOLID.

  • @vaishalijare8488
    @vaishalijare8488 7 лет назад

    Hi Chrish, Merry Christmas and in advance Happy New Year!
    Thanks. I learnt a lot from your videos. Could you please add video on ‘Design Pattern Cluster’?

  • @bobbyr8071
    @bobbyr8071 7 лет назад

    Great videos Chris, please make a vid on Visitor pattern. Thx

  • @alexdavies4121
    @alexdavies4121 3 года назад +1

    How about when integrating with other services and you have to check for a null response is a patter suitable for this, or when you check a database for a value and it is not there. I think these scenarios, conditionals are unavoidable.

  • @deathkillertech
    @deathkillertech 2 года назад

    Thanks

  • @hagopvittali3465
    @hagopvittali3465 6 лет назад

    Chris Thank you!, Please make a video about MVC pattern! we need to discuss about it a lot!!

    • @ChristopherOkhravi
      @ChristopherOkhravi  6 лет назад +1

      So MVC will most probably be a part of this series but unfortunately it might take a while before the video is dropped. Should drop some time during the summer though. Thanks for understanding and thanks a ton for watching the series :) :)

    • @hagopvittali3465
      @hagopvittali3465 6 лет назад

      Thank you my friend! we are waiting for your video about MVC, may the force be with u!

  • @FR12321
    @FR12321 7 лет назад +1

    Hey, it's a very interesting solution when the value null actually means "do nothing" but sadly it doesn't remove the need to check that a parameter is not null before using it...

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 лет назад

      Thanks a lot for the comment and for watching 🙂 🙂 If you never introduce nulls but rather instantiate a NullObject of the same type as the thing that you want to be null you can get pretty close to never having to check whether parameters are null. Or am I misunderstanding your point?

    • @FR12321
      @FR12321 7 лет назад +1

      What I mean is that when a method accepts a nullable it is still possible to pass it a null. So in practice, the code has to check for that in some way. To me, the null value is problematic because it breaks the inheritance tree : null can be a value of any nullable, whereas an Animal cannot be a value of type Cat (if Cat inherits from Animal)

  • @younessfathi1739
    @younessfathi1739 5 лет назад

    thank you

  • @cypherk
    @cypherk 6 лет назад

    Absolutely loved your videos, thanks a lot for these.
    What happened to the next, though?
    And for that matter, what happened to the book you mentioned you were writing a while ago?

  • @wobius
    @wobius 7 лет назад +6

    visitor pattern would be great :)

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 лет назад +1

      It will definitely come but I can unfortunately not make promises in regards to when :) Terribly sorry about the delay but thanks a ton for sticking with the channel! :) I'm glad that you appreciate the videos :) Happy hacking and thanks for commenting :)

    • @sv3167
      @sv3167 4 года назад

      exactly what I was about to write! Need another great explanation of design pattern

  • @josecarlosramirez486
    @josecarlosramirez486 7 лет назад +2

    New video! Yay!

  • @kesavanarayana6257
    @kesavanarayana6257 7 лет назад

    Hi Chrish, Can you make one video on, How to handle all exception at one place in custom library where we have hundreds of classes and all are independent to each other or may be we have different groups of classes (group is nothing but may be inherited from one abstract class or interface) instead of maintaing inside each method of a concrete type.
    What are the best practices to handle this kind of scenario.

    • @FR12321
      @FR12321 7 лет назад

      You can have a look at AppDomain.UnhandledException for logging purposes, ie. a log file, a messagebox to the user, ...
      But otherwise, exceptions are used to indicate a failure state and you have to handle them in the calling code if you can do something about it, ie. A ConnectionRetryDecorator could handle the exception of an IConnection and retry a number of times. I don't see how you would have all your exceptions handled in the same place without creating a huge smoke factory that will be painful to debug, ie. how would you handle both a connection exception and an argument exception in the same location?

  • @wittyhumour29
    @wittyhumour29 7 лет назад

    Hey Chris, as a self taught programmer what should I learn next (Data Structures & Algorithms) or (Design Patterns) ?
    I know/understand Object Oriented Programming :)

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 лет назад +2

      I would humbly vote data structures and algorithms. More fundamental in my mind. But this playlist should give you an idea of design patterns as well without having to invest too much time :) :) Best if luck!

    • @wittyhumour29
      @wittyhumour29 7 лет назад

      Thank you so much 😃 , I will now go for a book on Algorithms and Data Structures & will watch your videos from the Design Pattern Series. Thanks Again !

  • @armandormikopo
    @armandormikopo 6 лет назад

    Hi Christopher! Excellent job with this playlist. Do you have the intention of continuing it?

  • @이깨란
    @이깨란 4 года назад

    Great!

  • @kamilwitkowski2521
    @kamilwitkowski2521 Год назад

    the best !!!

  • @elhamnarangifard7569
    @elhamnarangifard7569 6 лет назад +1

    great job! I am just wondering why you havent made video on visitor DP yet!!

    • @ChristopherOkhravi
      @ChristopherOkhravi  6 лет назад +1

      Thanks :) Sorry about the long patterns break. I’ll continue the pattern series as soon as I can :)

  • @mko3294
    @mko3294 6 лет назад

    thanks man...

  • @B47UH4N99
    @B47UH4N99 9 месяцев назад

    It is like "continue" structure in for,while loop. It exists but is passing loop like nothing happened.

  • @auditore63
    @auditore63 Год назад

    Please make a video about the builder pattern

  • @strandedinthe0737
    @strandedinthe0737 4 года назад +1

    You awesome please move on, there is many another patterns, for example builder, saga, etc

  • @markomilojevic8792
    @markomilojevic8792 7 лет назад +11

    Hi Chris. I watched all of your videos and I have anything to say except - marvellous! I've already shared your videos to many guys, and all of them have same opinion.
    I have question. You are (maybe) the best presenter of design patterns, that I've ever seen, and I would like to see more it from you, and my suggestion would be to check patterns from second chapter in this book: martinfowler.com/books/eaa.html
    I guess this could be beyond scope for this topic, but maybe some separate playlist/topic/videos... just, do it! :D

    • @ChristopherOkhravi
      @ChristopherOkhravi  7 лет назад +1

      Thank you very much for the very kind words! And excellent suggestion! Much appreciated. I haven't read the book but I'll definitely look in to it. As you say, it probably deserves it's own playlist but either way I'll give the book a look! Thank you very much again :)

  • @sashatyurkina
    @sashatyurkina 7 лет назад

    Could you please also make video explaining Visitor Pattern?

  • @ahmedmahboub2199
    @ahmedmahboub2199 4 года назад

    is there any hope that ..this will be completed ?

  • @sticksen
    @sticksen 5 лет назад +1

    Isn´t this pattern kind of breaking Interface Segregation? Because you´re using an interface without really wanting to implement things...

  • @RC_mentoring
    @RC_mentoring 4 года назад

    looking at the comments it looks like you decided not to make any more videos on these design patterns. If you do Id be willing to send you some cash. I really like your high-level overview of these concepts.

  • @leonardoalfonso657
    @leonardoalfonso657 7 лет назад

    Hi man. It's possible if you can make two videos about Builder and Visitor Pattern? Thanks.

  • @yassineelattar5056
    @yassineelattar5056 7 лет назад

    Hello MasterAre there any other courses about Design Patterns coming up soon?You are doing a great Work by the way

  • @neweins8864
    @neweins8864 4 года назад

    Why this series is stopped? Now how would I learn? :(

  • @magicvortex
    @magicvortex 6 лет назад +1

    Will there be next one?

  • @AnotherFancyUser
    @AnotherFancyUser 6 лет назад

    Any chance you discuss Repository Pattern with/without Unit Of Work?

  • @arunprasad9716
    @arunprasad9716 6 лет назад

    Hi can you discuss about patterns for winforms in a desktop application.

  • @hugforfree
    @hugforfree 6 лет назад +1

    How about Chain of Responsability pattern? =)