This is a creation in Article, where the information may have evolved or changed.
1. Introduction
an interface refers to an abstraction that an entity provides itself to the outside world (another entity) that separates external communication methods from internal operations so that they can be modified internally without affecting the way other entities interact with the outside world. (from Baidu Encyclopedia)
2. Interfaces for other languages
Interface for Java
Public interface Animal {//define interface void Eat ();} The public class Dog {//is the same as the method name in the interface, but does not implement the Animal interface void Eat () {}}public class Cat implements Animal {///implements the Animal interface, And the Eat method must exist @Override void Eat () { }}
Interface for 3.Go languages
Package Mainimport ("FMT")//define an interface with Eat and Run two methods in the interface type Animal interface {Eat () run ()}//defines a dog entity class that implements the Animal interface type dog struct {}func (dog *dog) Eat () {fmt. Println ("I eat Bone")}func (dog *dog) Run () {fmt. Println ("I run very fast")}func Main () {//Call interface var a animala = &dog{}a.eat () A.run ()}
Operation Result: