Language My Go Tutorial

Interface with abstract of methods

Defining an Interface

type Interface_Name interface {
    Method_Name(Input) (Outputs)

Keyword : type, interface

Interface_name user provide a descriptive name

Within the { } curly bracket, method sets are a list of method_name has been defined method name with parameters, return. No implementation details.

type Speaker interface {
   Speak() string

type FileInfo
A FileInfo describes a file and is returned by Stat and Lstat.

type FileInfo interface {
    Name() string       // base name of the file
    Size() int64        // length in bytes for regular files; system-dependent for others
    Mode() FileMode     // file mode bits
    ModTime() time.Time // modification time
    IsDir() bool        // abbreviation for Mode().IsDir()
    Sys() interface{}   // underlying data source (can return nil)

the FileInfo interface has the following method sets:

Name() string // return a string

Size() int64 // return int64

Mode() FileMode // return FileMode type

ModTime() time.Time

IsDir() bool // return a bool type

Sys() interface{} // return an interface type