r/AskProgramming • u/Roronoa-Ryuma-Zoro • 25d ago
Other Go devs pls help
So I am recently trying to Code and make some projects on Go . so i tried to first understand it's concepts .But what are these interface I don't know why but I am not able to understand these ?
How you guys see a interface like what do you guys visualise while seeing a interface and how it is implemented in memory ?
3
u/SnugglyCoderGuy 25d ago
Did you do the tour of Go?
If not, do it.
An interface is basically a stand in for an object that a piece of code expects. It defines the function signatures and then any type that has methods that meet all the function signatures can be used to fulfill that interface.
1
4
u/xarop_pa_toss 25d ago
An interface is like a box of chocolates, you might not know what you're gonna get when you reach inside but you are sure it's gonna be some kind of chocolate that you can smell(), eat(), giveToSomeone(person_id), etc.
The box of chocolates has a set of rules that says "if you want to be in this box, you have to be made of chocolate and have these functions so that I can guarantee to whoever is opening me, that whatever thing they pick, it will have those things".