A Practical Example How To Use Interfaces In Golang

Sdílet
Vložit
  • čas přidán 17. 03. 2024
  • ► Join my Discord community for free education 👉 / discord
    ► Exclusive Lessons, Mentorship, And Videos 👉 / anthonygg_
    ► 33% OFF on my Go + HTMX + Templ Course PRESALE 👉bit.ly/3UFruxO
    ► Enjoy a 60% Black Friday Discount on My Golang Course 👉 fulltimegodev.com
    ► Learn how I became a self-taught software engineer 👉fulltimegodev.com/#mystory
    ► Follow me on Twitter 👉 / anthdm
    ► Follow me on GitHub 👉 github.com/anthdm
    Grab yourself a 33% OFF on the PRESALE event of my building production ready applications with GO + HTMX + Templ + Tailwindcss + JQuery course here: bit.ly/3UFruxO
    Golang interfaces: • This Will Make Everyon...
    Golang package context: • How To Use The Context...
    SUBSCRIBE OR NO MARGARITAS
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Komentáře • 36

  • @anthonygg_
    @anthonygg_  Před měsícem +2

    ► 33% OFF on my Go + HTMX + Templ Course PRESALE 👉bit.ly/3UFruxO
    ► Join my Discord community for free education 👉 discord.com/invite/Ac7CWREe58
    ► Exclusive Lessons, Mentorship, And Videos 👉 www.patreon.com/anthonygg_
    ► 60% OFF on my Golang course 👉 fulltimegodev.com
    Thanks for watching

  • @chandler828
    @chandler828 Před měsícem +40

    So much better than the overused geometry/shapes interface example. Well done.

    • @croncoder862
      @croncoder862 Před měsícem +3

      exactly, especially if you come from a Java or C# background, it looks really silly when people talk about all that

    • @wuiqed
      @wuiqed Před měsícem

      Like those OOP tutorials we all read when we first started learning programming. Create a Car class. Give it model and color properties. Add drive and honk methods. MyCar.honk(). "Beep, beep!" Ok, now what? How about a practical example? Fuck that, now you surely understand OOP, onto the next half-assed subject.

  • @croncoder862
    @croncoder862 Před měsícem +16

    You dropped this video just as I am building my own notifications engine in golang with support for various connectors🤣

    • @ada0015
      @ada0015 Před 17 dny

      I'm new to Golang (

    • @croncoder862
      @croncoder862 Před 7 dny

      @@ada0015 anywhere where you need a bunch of configs. moreover what anthony has shown here is an open ended design. meaning you wont have breaking api changes

  • @TannerBarcelos
    @TannerBarcelos Před měsícem +6

    The worst thing about interface tutorials, and the “polymorphism” examples in C++ classes in school, are the usual shape example.
    While it gets you going, it’s not practical at all.
    This tutorial made the whole paradigm so much easier to understand.

  • @RagavsathisChinnu
    @RagavsathisChinnu Před 12 dny

    good explanation, I was confused coming from Python on how I can use factory pattern.
    This is crisp to point, thanks !

  • @user-sc5pw5cw5n
    @user-sc5pw5cw5n Před 10 dny +1

    The video demonstrates how to refactor a simple Go application to use interfaces, highlighting the benefits of dynamic behavior and testability.
    Key moments:
    00:01 Interfaces can be confusing for people, but using them in applications can clarify their purpose and benefits, especially for those aspiring to be Go engineers.
    -Creating a simple application to demonstrate interface usage can help developers understand when and how to utilize interfaces effectively.
    -Implementing a notification system with different methods like email, SMS, or Slack can showcase the versatility of interfaces in handling various functionalities.
    03:41 The video discusses refactoring code to use interfaces, emphasizing the importance of error handling and context in Go programming. It also touches on dependency injection and state management in code design.
    -Importance of error handling and context in Go programming for interfaces. It highlights the significance of returning errors and using context to manage timeouts and cancellations.
    -Discussion on dependency injection in code design, focusing on the need for a mechanism to attach state to handlers. It explains the concept in the context of creating a struct for account handling.
    07:24 The video discusses implementing an account Notifier interface in Go programming language, creating a simple account Notifier structure, and utilizing the context package for handling notifications efficiently.
    -Creating an instance of the account Handler and implementing the account Notifier interface for handling account notifications efficiently.
    -Utilizing the context package for handling notifications and demonstrating a simple implementation of account notifications in Go programming.
    11:31 Using interfaces in Go can allow for dynamic and flexible code changes, as demonstrated by swapping account notifier implementations easily. It showcases the power and versatility of interfaces in Go programming.
    -Demonstrating how to swap account notifier implementations by passing a new implementation, showcasing the flexibility of interfaces in Go programming.
    -Discussing the appropriate use of interfaces in Go, highlighting the importance of interfaces for attaching state in certain implementations like API Keys or caching systems.

  • @macot79
    @macot79 Před měsícem +1

    Fantastic video Anthony, thanks a lot!

  • @zevo92
    @zevo92 Před měsícem +1

    Great exemplification of a good practice by using simple yet powerful patterns. I think a video showing "the over-engineering" use of interfaces would also be nice :D

  • @TheMouseJerry-du1md
    @TheMouseJerry-du1md Před 4 dny

    Brilliant yet concise video.

  • @coffeeintocode
    @coffeeintocode Před měsícem +1

    Yeah this is great stuff. As always 🔥

  • @juanitoMint
    @juanitoMint Před 17 dny

    Great Explanation with a useful example, I would love to see in this particular example a way to chain multiple Notifiers in a slice!

  • @ThePandaGuitar
    @ThePandaGuitar Před měsícem +1

    i love these high level golang videos that focus on patterns

  • @MrEsherbek
    @MrEsherbek Před měsícem +1

    Spent time wonderfully.

  • @michaelrichter9408
    @michaelrichter9408 Před měsícem +3

    Which Rest API VS Code extension do you use? Great video. Thanks.

  • @stefanbogdanovic590
    @stefanbogdanovic590 Před měsícem

    or you can attach preference property on Account and create NotificationFactory which creates proper implemntation then you don't have to change anything just create new impl. Awesome video!

  • @Noudapi
    @Noudapi Před měsícem +1

    Hey Anthony, thanks for the great video. For a next video, would it be possible to see how you would implement storage interfaces in an API? You started something like in a previous video "how to structure a go project".

  • @fartknockers
    @fartknockers Před měsícem +3

    Excited for this!

  • @sefpai424
    @sefpai424 Před měsícem +1

    very easy to understand explanation

  • @MT87840
    @MT87840 Před měsícem

    Thanks so much!

  • @Leeway4434
    @Leeway4434 Před měsícem

    I'm thinking about how to build htmx+templ forms using interfaces for different form input types. We always have value+error strings for form params--we can make an interface to fill them in programmatically. So we can define a form as a slice of FormInputType enums and have the interface implementation fill out the template with those form inputs from the slice. For example, FormInputType{UsernameInput,PasswordInput} can be passed to some form builder with the value/error params

  • @ramazangCoder
    @ramazangCoder Před měsícem

    Great!!❤
    Anthony Can you show builtin golang Interface and examples for brain ruins 😄

  • @croncoder862
    @croncoder862 Před měsícem +1

    One question, in this video you changed the behaviour by swapping the implementation, but what if I have a few structs that carry configurations and each implementation has a different configuration. Is there a way to address that?

  • @walidsi71
    @walidsi71 Před měsícem +1

    Thanks for the video. What is the extension you use in vscode for creating http requests in a new tab to test the code?

  • @cybermindable
    @cybermindable Před měsícem

    Why is changing or creating a new notifier strictly better than modifying the handler?

  • @mayoniaise5169
    @mayoniaise5169 Před měsícem

    why make a state for an API key as the context value is made for that ?

  • @raoulkent
    @raoulkent Před měsícem

    Hi Anthony, really great video as always, it's much appreciated by many.
    I was wondering if you've got anything in the pipeline, or considered, putting out some "go gym" type videos. And by that I mean smaller exercises that people can do in order to get better.
    TLDR: Are you considering project suggestions as part of your content?

  • @ArturdeSousaRocha
    @ArturdeSousaRocha Před měsícem +2

    Anyone know what color theme Anthony is using?

  • @fullstack_journey
    @fullstack_journey Před měsícem +1

    Go daddy

  • @wew8820
    @wew8820 Před 6 dny

    a bit like strategy pattern

  • @sabbirhasan6934
    @sabbirhasan6934 Před měsícem +1

    The most confusing video on interface i've seen so far!