Interface Method

An interface type specifies a set of methods called its interface. An interface type variable can store a value of any type with a set of methods that is any superset of the interface.


// Interface of a file
interface {
  Read(b Buffer) bool
  Write(b Buffer) bool
  Close()
}
                        

More than one type can implement an interface. Example, if two types S1 and S2 have method defined.


func (p T) Read(b Buffer) bool { return … }
func (p T) Write(b Buffer) bool { return … }
func (p T) Close() { … }
                        
interface_method.go