#40 Golang - Understanding Interfaces and Generics in Go: Real-World Examples

preview_player
Показать описание
Welcome back to our Go programming series! Today, we're diving into two powerful features of Go: Interfaces and Generics. One of the most confusing concepts for developers is understanding the difference between these two and where to use what. We'll explore what they are, why they're useful, and see some real-world examples. Let's get started!

Topics Covered:
- Understanding Interfaces
  - Definition and purpose
  - Implementing polymorphism
  - Promoting loose coupling and improving testability
- Real-World Example: Payment Processing System
  - Types: Credit Cards, PayPal, Bank Transfers
  - Interface: PaymentProcessor
  - Implementing the ProcessPayment method
  - Processing payments with the PaymentProcessor interface
- Introduction to Generics
  - Definition and purpose
  - Reducing code duplication
  - Enhancing readability and type-safety
- Real-World Example: Generic Sorting Function
  - Defining constraints with the Sortable interface
  - Implementing a generic sorting function
  - Sorting slices of different types (integers, floats, strings)

By understanding and using these features, you can build more robust and scalable applications. Thanks for watching, and happy coding!

Resources:

Timestamps:
00:00 - Introduction
00:28 - Interfaces
03:09 - Generics
05:03 - Concluding remarks

Don’t forget to like, subscribe, and hit the bell icon for more Go programming tutorials!

------------------------------------------------------------------------------------------------------------------------------

Buy my book 'Functional Programming with Go' here:
Рекомендации по теме
Комментарии
Автор

Hi, professor? I'm a developer of Newbie who started Golang for fun. I got a lot of help from watching your videos. Thank you so much

Based on this, I'm planning a project with gin-gonic, and I have one thing I'm thinking about

I've used the spring framework so far, and the spring has a controller-service-repository (db access) structure, and all the repository tasks within the service (even if you call another service from within the service) can operate as one transaction

I don't know how to code this "elegantly" in go

Should I keep the DB object in the service and create a transaction so that both the service and repository receive and operate this transaction object? Neither Googleing nor ai gave me a satisfactory answer

Can you deal with this problem?

김지헌-he
Автор

Generics are really awesome.. but many of codebase still not adopting this.

Mr.BinarySniper
Автор

Why aren't your videos getting thousands of views🤯. Your content is so well developed and direct.

codelinx