How to declare Interface Type in Go Programming Language
An Interface is an abstract type.
Interface describes all the methods of a method set and provides the signatures for each method.
To create interface use interface keyword, followed by curly braces containing a list of method names, along with any parameters or return values the methods are expected to have.
An interfaces act as a blueprint for method sets, they must be implemented before being used. Type that satisfies an interface is said to implement it.
Example
// Declare an Interface Type and methods does not have a body
type Employee interface {
PrintName() string // Method with string return type
PrintAddress(id int) // Method with int parameter
PrintSalary(b int, t int) float64 // Method with parameters and return type
}
Most Helpful This Week
Interface Accepting Address of the Variable in Golang
Interface embedding another interface in Go Programming Language
Interfaces with similar methods in Go Programming Language
Defining a type that satisfies an interface in Go Programming Language
Polymorphism in Go Programming Language
Empty Interface Type in Go Programming Language
Implementing Multiple Interfaces in Go Programming Language