Golang Interface Basics You MUST Know!!
HTML-код
- Опубликовано: 28 май 2024
- Golang Interfaces - ULTIMATE Golang Basics Tutorial
In today's Golang tutorial video, we will talk about the Interfaces in Go. We will go through how to implement interfaces in the Go programming language, along with some comparisons with more traditional OOP languages like Java, and everything you need to know to fully understand Interfaces in Go/Golang. Enjoy!
--
Golang Dojo is all about becoming Golang Ninjas together. You can expect all kinds of Golang tutorials, news, tips & tricks, and my daily struggles as a Golang developer. Make sure to subscribe if you look forward to such content!
Get Your Golang Cheat Sheet! - golangdojo.com/cheatsheet
Git repos & notes - golangdojo.com/resources
Golang Basics - www.youtube.com/watch?v=VTJ8q...
Timestamps
0:00 Intro
0:24 Code Setup
2:42 Implementing Interfaces
3:45 Duck Typing
6:15 Outro
--
#golang #goprogramming #golangdojo - Наука
📝Get your *FREE Golang Cheat Sheet* -
golangdojo.com/cheatsheet
Honestly one of the best explanations of interfaces. This channel is quickly becoming my go-to for golang!
True
rly good explanation, without abstract shit
This channel became my instant go-to for Golang 🤣
This topic is the most confusing for me as a new Go programmer, but you helped make it make (a bit more) sense. Thanks!
Great to hear!
it's simple yet easy to understand. WHY IN THE WORLD others showing interfaces along with crazy math on how to calculate square + circle. KISS
I saw videos i also read many articles and didn't understand a thing, but i swear you just made it looks so easy to understand Thank you!
Glad it helped!
Greate video man you really simplify things and make it easy to understand.
Thank you! More to come!
Thanks for the great tutorial, I have a quick question on declaring function 🤔🤔
Is there a reason why you didn't call weapon.attack() directly inside the loop? What's the best practice there?
Thank you Sensei
Anytime!
can a function belong to 2 interfaces / struct ?
where did you get this keyboard? is it smooth? can you share the link?
Good video.
Great tutorial, I like your channel :)
Glad to hear that!
How would you write an interface to the Record function shown below?
type Total1 struct {
tot1 float64
}
func (t *Total1) Record(x float64) {
t.tot1 += x
}
type addition interface{
record()
}
// accepts values of type addition interface and num to call record
func calculateTotal(t addition, num float64) {
t.record(num)
}
func main() {
t := total1{ 1.2 }
calculateTotal( &t, 3.3)
}
Hope this helps ☺
@cychoboy
How would you print out the names of the Ninja's that use the weapon in this code example?
Ah got it:
for _, weapon := range weapons {
a := fmt.Sprintf("%s", weapon)
fmt.Printf("%s ", strings.Trim(a, "{}"))
attack(weapon)
} // Output: Wallace uses sword
Figured I could just do weapon.owner too.
@@gwnbw I know you posted this a couple of month ago, but you can do that. if your struct method is like this:
func (n ninjaStar) attack() {
fmt.Printf("%s uses ninja star
", n.owner)
}
Then that should print out with the owners name
your voice is not ok.
I want to be Ninja!