Go Interface

Go has different approaches to implement the concepts of object-orientation. Go does not have classes and inheritance. Go fulfill these requirements through its powerful interface.

Interfaces provide behavior to an object: if something can do this, then it can be used here.

An interface defines a set of abstract methods and does not contain any variable.

syntax:

where Namer is an interface type.

Generally, the name of an interface is formed by the method name plus the [e]r suffix, such as Printer, Reader, Writer, Logger, Converter, etc.

  • A type doesn't have to state explicitly that it implements an interface: interfaces are satisfied implicitly. Multiple types can implement the same interface.
  • A type that implements an interface can also have other functions.
  • A type can implement many interfaces.
  • An interface type can contain a reference to an instance of any of the types that implement the interface

Go Interface Example

Output:

Accelrating...
I am toyota, I accelerate fast...
{suzuki blue}
{Toyota Red 100}

Next TopicGo Pointer




Contact US

Email:[email protected]

Go Interface
10/30