This is a creation in Article, where the information may have evolved or changed.
Extended
The previous article talked about implementing all the methods in an interface.
If you implement more than one interface, it is also very simple, the same way that his method to implement the line.
Background:
There is an animal interface, he has the action of eating and running, suddenly a bird animal, yes, it can fly.
If we modify the interface animal plus the action of flying, this will let the dog also fly. So, we put the methods of the interface out separately.
Package Mainimport ("FMT")//Fly interface type IFly interface {fly ()}//eating interface type IEat interface {Eat ()}//run interface type Irun interface {Ru N ()}//the implementation class of the dog type, "dog" struct {name String}func (dog *dog) Eat () {fmt. Println (Dog.name + "Eat")}func (dog *dog) Run () {fmt. Println (Dog.name + "Run")}//Bird Implementation class type Bird struct {name String}func (Bird *bird) Fly () {fmt. Println (Bird.name + "Fly")}func (bird *bird) Eat () {fmt. Println (Bird.name + "eat")}func main () {var eat IEat = &dog{"Dog"}eat. Eat () Eat = &bird{"Bird"}eat. Eat () var run irun = &dog{"Dog"}run. Run () var fly IFly = &bird{"Bird"}fly. Fly ()}
Run results
Summarize:
Golang implements the interface as long as the implementation class implements all the methods in the interface, we call the implementation class to implement the interface.