A Practical Example How To Use Interfaces In Golang

Поделиться
HTML-код
  • Опубликовано: 17 мар 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
    ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
    ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
    ╠╗║╚╝║║╠╗║╚╣║║║║║═╣
    ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

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

  • @anthonygg_
    @anthonygg_  2 месяца назад +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 2 месяца назад +44

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

    • @croncoder862
      @croncoder862 2 месяца назад +3

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

    • @wuiqed
      @wuiqed 2 месяца назад

      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 2 месяца назад +17

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

    • @ada0015
      @ada0015 Месяц назад

      I'm new to Golang (

    • @croncoder862
      @croncoder862 Месяц назад

      @@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 2 месяца назад +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.

  • @ThePandaGuitar
    @ThePandaGuitar 2 месяца назад +1

    i love these high level golang videos that focus on patterns

  • @zevo92
    @zevo92 2 месяца назад +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

  • @macot79
    @macot79 2 месяца назад +1

    Fantastic video Anthony, thanks a lot!

  • @TheMouseJerry-du1md
    @TheMouseJerry-du1md Месяц назад

    Brilliant yet concise video.

  • @MrEsherbek
    @MrEsherbek 2 месяца назад +1

    Spent time wonderfully.

  • @michaelrichter9408
    @michaelrichter9408 2 месяца назад +3

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

  • @juanitoMint
    @juanitoMint Месяц назад

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

  • @user-sc5pw5cw5n
    @user-sc5pw5cw5n Месяц назад +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.

  • @RagavsathisChinnu
    @RagavsathisChinnu Месяц назад

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

  • @coffeeintocode
    @coffeeintocode 2 месяца назад +1

    Yeah this is great stuff. As always 🔥

  • @sefpai424
    @sefpai424 2 месяца назад +1

    very easy to understand explanation

  • @Noudapi
    @Noudapi 2 месяца назад +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".

  • @stefanbogdanovic590
    @stefanbogdanovic590 2 месяца назад

    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!

  • @MT87840
    @MT87840 2 месяца назад

    Thanks so much!

  • @Leeway4434
    @Leeway4434 2 месяца назад

    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

  • @croncoder862
    @croncoder862 2 месяца назад +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?

  • @fartknockers
    @fartknockers 2 месяца назад +3

    Excited for this!

  • @walidsi71
    @walidsi71 2 месяца назад +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?

  • @ramazangCoder
    @ramazangCoder 2 месяца назад

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

  • @rajughorai7483
    @rajughorai7483 14 дней назад

    🎯 Key Takeaways for quick navigation:
    00:00 *🛠️ Interfaces in Go can be confusing for some, especially regarding when and how to use them effectively.*
    01:36 *📡 Implementing a notification system after specific actions in your application is a common practice, such as notifying users or admins via various channels.*
    03:42 *🔄 Refactoring code to use interfaces is beneficial for scenarios where implementations may vary, such as different notification methods.*
    06:14 *⏳ When designing systems with potential IO operations, using contexts is crucial for managing timeouts and ensuring application determinism.*
    08:32 *📜 Dependency injection through interfaces allows for flexible and dynamic behavior without modifying core logic repeatedly.*
    11:44 *🔄 Utilizing interfaces enables easy swapping of implementations, improving code flexibility and maintainability.*
    13:54 *🔥 Proper understanding and usage of interfaces in Go can lead to more idiomatic, composable, and maintainable code.*

  • @cybermindable
    @cybermindable 2 месяца назад

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

  • @ArturdeSousaRocha
    @ArturdeSousaRocha 2 месяца назад +2

    Anyone know what color theme Anthony is using?

  • @mayoniaise5169
    @mayoniaise5169 2 месяца назад

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

  • @raoulkent
    @raoulkent 2 месяца назад

    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?

  • @fullstack_journey
    @fullstack_journey 2 месяца назад +2

    Go daddy

  • @wew8820
    @wew8820 Месяц назад

    a bit like strategy pattern

  • @sabbirhasan6934
    @sabbirhasan6934 2 месяца назад +2

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