Why don't we embed interface into structures? For example, If you intend to make a structure implement an interface, simply add "implement interface_name" in structure definition. That will add clarity in code. Right?
I've been struggling with how interfaces work for a while now and I think this video finally got it to click for me. Thank you.
The kind of thinking of interfaces being a contract is not wrong, but kinda abstract. Think of an interface as a membership, named after whatever you decide to call your interface, in this case "Shape". For any struct/class that wants to have that membership, they have to implement the functions described in that interface, much like how you may want to meet certain criteria to have a gym membership. So for Circle and Rectangle, they have to implement all Shape functions/methods to have a Shape membership. This is convenient because perhaps there could be a function somewhere that only takes Shape members to operate on them (calculateArea), and if Circle and Rectangle are Shape members, that function can operate on either one of them
Hey Flo, just wanted to say how much I like your teaching style. Your videos are great! Please cover more advanced Golang topics such as Go concurrency patterns and best practices. Thank you!
Damn man, that was a direct hit. So clear and tqsm
Thanks for the video, the explanations are easy to understand. One thing I didn't fully get is how by passing the CalculationError{msg: "Invalid input"} struct instance on the performCalculation() the performCalculation() would use the Error() method of the CalculationError struct, I would've thought that we would need to call the Error() method of the struct but this is not the case, so what I gather with this is that the compiler implicitly deduces that since we are returning a value of type error and because we're using the CalculationError{msg: "Invalid input value"} struct instance as its return value it "sees" that this struct instance has a method that implements the Error() function and hence it uses it. So this is some sort of implicit default method for specific type returns or something like that, I honestly don't no how to refer to this behavior, I had no knowledge if this behavior but is good to know. Thanks again for putting this video together.
This teacher is so logical, thanks!!
I've never seen someone explain something that clearly
Bro everything in this video is amazing, the quality of the explanation, camera, audio and code examples, thanks for this excelente tutorial
Ahh, such a lovely explanation! Finally clicked for me how and why Error interface works!
5:00 , you said if you added a new method in the shape interface , then the rectangle interface no longer implements it. That is in order for a struct to implement the interface it should implement all the methods of that interface . But Go interfaces are loosely coupled right ?a struct can implement part of the interface . I tried out the code to confirm it and the code still works . Am i interpreting it wrong or missing something here?
I'm new to Go and your video's help me a lot, thanks 🙏. Keep it up 💪
but you only covered struct implementing interface can you please make video on function type implemention interface - this pattern is used in gorilla mux and in many golang std packages .. please cover this
Nice video, I was wondering what is the theme and IDE? it looks way more cleaner that my typical Goland. Thanks in advance!
i would a love a deeper dive into this if possible smth that explains how interfaces work under the hood and why go interfaces would be faster or better than lets say c# interfaces or smth else
Nice video, but on the language accordance with logic of interface design, let's said that a Shape has a perimeter. So it does reduce the understand about what is the idea to implement a new interface to any duty contract. I would better think about Position as a new interface. Because a shape will have any area, perimeter by logic. But the position it can have is not due to the fact it is a shape, but because this shape can be somewhere. So, for example, An interface named Object can be the resulted union about Shape and Position. This (in my mind) is the way to think about contract interface in Golang (and most probably, in interface in general). Tell me if you are ok with this observation, please.
So in golang you can enforce methods when you implement an interface. Example in rust if you do impl interface for struct {} You'll need to add all the functions which are defined in the interface. Else, code won't compile.
As far as I've understood it, they're basically like a class in C++ where everything is virtual. Generally we'd refer to that as an abstract class. That and error codes instead of exceptions I copied as features for my own language. I don't like that they use it as a sort of replacement for genericity syntax though. It's basically another void pointer, but with the requirements for casting turned 180 degrees. So better, but not good enough in my opinion. Looks like you do both Rust and Go, but perhaps you should add more languages to your repertoire like plain C and demonstrate how different constructs work at a fundamental level by converting them to C.
I really look Go as an easy and readable language, because once you have touch with OOP, Aspect, and other suff famous on java world everything is possible to overcome
@rhysmuir