FINALLY, the Visitor Design Pattern makes Sense

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • Let's explore the Visitor Design Pattern while we refactor C# dotnet code.
    💎 Be a Patreon to get the source code: / gsferreira
    🚨 KEY LINKS
    🤝 Support me on Patreon (and get access to source code) here: / gsferreira
    👋 HEY FRIEND
    If you're new to my Channel, my name is Guilherme, but you can call me Gui if Portuguese pronunciation is not your thing.
    I see myself as a Minimalist Software Craftsman. That says a lot of what I talk about here.
    So, why this TH-cam channel? To share with you to simplify your life as a Developer through knowledge, technology, and practices.
    If you are into those things as I do, don't forget to subscribe for new videos.
    🔗 GET IN TOUCH
    LinkedIn: / gferreira
    Twitter: / gsferreira
    GitHub: github.com/gsf...
    Visit my blog: gsferreira.com
    #dotnet #csharp

ความคิดเห็น • 26

  • @JohnOliverAtHome
    @JohnOliverAtHome ปีที่แล้ว +7

    Thanks Gui. Loved the (dynamic)this hint. It makes perfect sense and is so simple (now that I've seen it)

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว +1

      Great to hear, John! Thanks for taking the time to leave a comment.

  • @tristanstricker967
    @tristanstricker967 ปีที่แล้ว +4

    Great video. I think the strategy pattern may be a better fit for this example but visitor is still great. You are making great c# content. Keep up the good work

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว +1

      Thanks! I think the Strategy Pattern can solve the same problem but doesn't give you the same benefits as the Visitor when you have a Composite.
      Thanks for the kind words, Tristan!

  • @stevancosovic4706
    @stevancosovic4706 9 หลายเดือนก่อน +1

    Very good explanation, thanks!

    • @gui.ferreira
      @gui.ferreira  9 หลายเดือนก่อน

      Glad you enjoyed it!

  • @franciscoamaral9834
    @franciscoamaral9834 ปีที่แล้ว +1

    Hi Gui, can you tell me what IDE are you using?

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว

      Hey Francisco!
      JetBrains Rider.

  • @jeffg4686
    @jeffg4686 5 หลายเดือนก่อน +1

    The problem with the visitor pattern is fundamental.
    It breaks readability. It lacks domain understanding.
    To "Visit" isn't a verb with meaning.

    • @ppg68
      @ppg68 2 หลายเดือนก่อน

      While I agree, I find the idea of isolating the Methods into Objects quite useful, you only have to modify the code in one class without breaking anything else

    • @jeffg4686
      @jeffg4686 2 หลายเดือนก่อน

      @@ppg68 - I'm needs based. I never really found a need for this pattern. And when I see it used, it's never relevant, reads horrible, and fails to convince me that I need it. Just like the bridge pattern. Things start getting too pattern happy after a while...

  • @Autumn4_love_your_
    @Autumn4_love_your_ ปีที่แล้ว +1

    Its a replacement for a type switch case

  • @AndersBaumann
    @AndersBaumann 8 หลายเดือนก่อน +1

    The visitor is an attempt to implement a functional pattern in an OO language. But C# is getting more functional so now the visitor pattern can elegantly be replaced by pattern-matching expressions.

  • @vijaybhargavg8638
    @vijaybhargavg8638 ปีที่แล้ว +2

    This was brilliant.

  • @ilovepandaypoe6056
    @ilovepandaypoe6056 ปีที่แล้ว +1

    real world scenario, all those permutations will be stored in the database? so need really to create many classes?

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว +2

      You don't need to apply the visitor design pattern to domain or DB objects. It's a useful pattern for things like parsing or formatting

  • @MizenDaCat
    @MizenDaCat ปีที่แล้ว +1

    Hi Gui, do you have a video going through your IDE setup (themes, fonts, extensions)? If not, I think you should make one. What font are you using in this video?

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว

      Hi! Thanks for the suggestion. I'm not sure if I want to do a video on this channel about it, but I will try to find a way to have that information out there.
      Regarding the Font, on the video, I'm using JetBrains Mono.

  • @FreeMindInMotion
    @FreeMindInMotion ปีที่แล้ว +1

    Nice video. I have never used the pattern, but I will keep my eyes open.
    I like the dynamic type hint for the base class

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว

      Glad you liked it 🙏
      In fact, it's rarely used but it's good to know how it works.

  • @asusvenus
    @asusvenus ปีที่แล้ว +1

    Great content. Although, I think its way too zoomed in

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว

      That's great feedback! Thanks! I've been using Presentation mode lately. I will revisit it 😉

  • @HizusHiz
    @HizusHiz 10 หลายเดือนก่อน

    Still doesn't make sense for c# because you can use pattern matching which will be faster.

  • @vitek0585
    @vitek0585 ปีที่แล้ว +1

    As option the extension methods for the particular type can replace this pattern

    • @gui.ferreira
      @gui.ferreira  ปีที่แล้ว

      Not that you can't do it in other ways in C#, but even then, it's not an "apples to apples" comparison.