Mediator Design Pattern In Action! - C# Design Pattern Tutorial

Поділитися
Вставка
  • Опубліковано 29 вер 2024
  • In this video, we'll be exploring the mediator design pattern. This design pattern is used to manage communication between different objects. We'll navigate a small sample application using the mediator design pattern and C#.
    If you're interested in learning more about design patterns or want to learn how to use C# to create powerful applications, this video is for you! By the end of this video, you'll have learned everything you need to know about the mediator design pattern and how to use it in your own projects.
    Have you subscribed to my weekly newsletter yet? A 5-minute read every weekend, right to your inbox, so you can start your weekend learning off strong:
    subscribe.devl...
    Check out all of my courses:
    devleader.ca/c...
    Check out more Dev Leader content (including full in-depth articles with source code examples) here:
    linktr.ee/devl...
    Social Media:
    - Blog: www.devleader.ca/
    - Newsletter: www.devleader....
    - TikTok: / devleader
    - LinkedIn: / nickcosentino
    - Threads: threads.net/@dev.leader
    - Twitter: / devleaderca
    - Facebook: / devleaderca
    - Instagram: / dev.leader
    - GitHub: github.com/nco...
    - Twitch: / ncosentino
    - UA-cam: / @devleader
    Affiliations & Products/Services That I Love:
    - VPS hosting from RackNerd: my.racknerd.co...
    - VPS hosting from Contabo: www.jdoqocy.co...
    - My newsletter platform ConverKit: convertkit.com...
    - My newsletter referral system SparkLoop: dash.sparkloop...
    - My AI shorts helper Opus Clip: opus.pro/?via=...
    - I try to help answer questions at Quora: www.quora.com/...
    - My favorite computer parts store Newegg: click.linksyne...
    - My favorite supplement store Bulk Supplements: glnk.io/63qn/d...
    #softwareengineering #softwaredeveloper #designpattern #designpatterns

КОМЕНТАРІ • 11

  • @DevLeader
    @DevLeader  10 місяців тому

    😲😲 My new course has launched! You can check out Refactoring for C# Devs on Dometrain:
    dometrain.com/course/from-zero-to-hero-refactoring-for-csharp-developers
    📌 Remember to subscribe to my free weekly software engineering newsletter:
    subscribe.devleader.ca

  • @liangbinyu7620
    @liangbinyu7620 28 днів тому +1

    It would be perfect if you had tutorials regarding all design patterns,really look forward to watching all the high quality educational videos!

    • @DevLeader
      @DevLeader  28 днів тому

      @@liangbinyu7620 I started off in that direction 😅 it's even on my whiteboard to get through more of them.
      Thanks for the feedback!

  • @VishnuPriya-ng6wk
    @VishnuPriya-ng6wk 9 місяців тому +1

    Why should ChatUser have an instance of mediator? why cant it be a static class?

    • @DevLeader
      @DevLeader  9 місяців тому +2

      This is a great question. In fact, it absolutely could be static.
      However - You'll find in nearly all of the content I produce that I don't show usage of static classes. Some exceptions are utility or extension methods, or in mostly edge cases where composition doesn't work.
      The reason I avoid them, in general, is to help support testability. In this simple example we could certainly get away with it. I don't have a strong argument here. However, if our classes were slightly more complex and you wanted to start writing tests on them, static classes make this a total pain in the butt. They're shared across the entire runtime of the app/tests, and if they have state that can be mutated it's game over. If they interact with external systems, you have no choice but to interact with those systems (no mocking or otherwise intercepting in tests).
      I hope that helps explain why I generally won't do that (but you're certainly correct that it would be functional).

    • @VishnuPriya-ng6wk
      @VishnuPriya-ng6wk 9 місяців тому +1

      @@DevLeader , thanks for the reply. Why are static classes hard to test? In other words, how making them non static helps with mocking?

    • @DevLeader
      @DevLeader  9 місяців тому +2

      @@VishnuPriya-ng6wk when they are normal classes with interfaces we can use mocking frameworks. The mock only needs to meet the interface and not the concrete class, and since static classes cannot have interfaces you don't get this luxury.
      Static classes make things more challenging to test based on how complex they are. If you have simple methods, truly it's not very difficult. But if you are executing a lot of code in a static method, consider that anyone trying to write a unit test will not have *any* control over that static method. They need to have everything set up properly for the static code to execute properly
      It can get so complex that it makes writing unit tests difficult, or brittle/flakey when running in parallel.
      It's not to say they cannot be used, but I've seen too many instances where they cause a ton of headaches. I design to not use them, and when I do, they're very lightweight 🙂

  • @bloggrammer
    @bloggrammer 10 місяців тому +1

    Great content, Nick. I would first normalize the user Name property at 9:31

    • @DevLeader
      @DevLeader  10 місяців тому +1

      Thanks so much!
      And you're right - the user name thing was a bit of a gotcha moment when I was recording this thinking I might not have planned to cover that well enough. Poor planning on my part 😕

  • @EminoMeneko
    @EminoMeneko 8 місяців тому +1

    Thanks. That was interesting.

    • @DevLeader
      @DevLeader  8 місяців тому

      Glad that you enjoyed it!