A Practical Example How To Use Interfaces In Golang

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ก.พ. 2025

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

  • @anthonygg_
    @anthonygg_  10 หลายเดือนก่อน +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 10 หลายเดือนก่อน +74

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

    • @croncoder862
      @croncoder862 10 หลายเดือนก่อน +5

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

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

      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 10 หลายเดือนก่อน +25

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

    • @ada0015
      @ada0015 9 หลายเดือนก่อน

      I'm new to Golang (

    • @croncoder862
      @croncoder862 9 หลายเดือนก่อน

      @@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

  • @ThePandaGuitar
    @ThePandaGuitar 10 หลายเดือนก่อน +2

    i love these high level golang videos that focus on patterns

  • @zevo92
    @zevo92 10 หลายเดือนก่อน +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

  • @juanitoMint
    @juanitoMint 9 หลายเดือนก่อน

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

  • @macot79
    @macot79 10 หลายเดือนก่อน +1

    Fantastic video Anthony, thanks a lot!

  • @MrEsherbek
    @MrEsherbek 10 หลายเดือนก่อน +2

    Spent time wonderfully.

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

    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!

  • @sondernfy
    @sondernfy 6 หลายเดือนก่อน

    That was beautiful. Instantly subscribed!

  • @michaelrichter9408
    @michaelrichter9408 10 หลายเดือนก่อน +4

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

    • @LourensRolograaf
      @LourensRolograaf 6 หลายเดือนก่อน +1

      I think it is Thunder Client

    • @sondernfy
      @sondernfy 6 หลายเดือนก่อน +1

      @@LourensRolograaf Correct!

  • @Noudapi
    @Noudapi 10 หลายเดือนก่อน +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".

  • @TheMouseJerry-du1md
    @TheMouseJerry-du1md 9 หลายเดือนก่อน

    Brilliant yet concise video.

  • @coffeeintocode
    @coffeeintocode 10 หลายเดือนก่อน +1

    Yeah this is great stuff. As always 🔥

  • @TannerBarcelos
    @TannerBarcelos 10 หลายเดือนก่อน +8

    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.

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

    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

  • @walidsi71
    @walidsi71 10 หลายเดือนก่อน +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?

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

      Thunder client

  • @sefpai424
    @sefpai424 10 หลายเดือนก่อน +1

    very easy to understand explanation

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

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

  • @croncoder862
    @croncoder862 10 หลายเดือนก่อน +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?

    • @tuanvumaihuynh
      @tuanvumaihuynh 3 หลายเดือนก่อน

      U can pass the config when initialize your implementation

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

    🎯 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.*

  • @ArturdeSousaRocha
    @ArturdeSousaRocha 10 หลายเดือนก่อน +2

    Anyone know what color theme Anthony is using?

    • @anthonygg_
      @anthonygg_  10 หลายเดือนก่อน +2

      Gruvbox

  • @MargaretHamilton-h5k
    @MargaretHamilton-h5k 9 หลายเดือนก่อน +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.

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

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

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

    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?

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

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

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

    Thanks so much!

  • @fullstack_journey
    @fullstack_journey 10 หลายเดือนก่อน +2

    Go daddy

  • @wew8820
    @wew8820 9 หลายเดือนก่อน

    a bit like strategy pattern

  • @sabbirhasan6934
    @sabbirhasan6934 10 หลายเดือนก่อน +4

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