Skip to content

Instantly share code, notes, and snippets.

@MuthukumarHelios
Created March 5, 2018 06:54
Show Gist options
  • Save MuthukumarHelios/0218ede8c40eb0594f42f50878132b2c to your computer and use it in GitHub Desktop.
Save MuthukumarHelios/0218ede8c40eb0594f42f50878132b2c to your computer and use it in GitHub Desktop.
Struct vs interface
package main
import "fmt"
type student struct{
name string
age int
lastName string
}
type studentI interface{
GetAge() int
GetFullName() string
GetName() string
}
func StudentDetails(si studentI){
fmt.Println(si)
fmt.Println("student age",si.GetAge())
fmt.Println("student Full name", si.GetFullName())
fmt.Println("student Name", si.GetName())
}
func (s student) GetAge() int {
return s.age
}
func (s student) GetFullName() string{
return s.name + s.lastName
}
func (s student)GetName() string{
return s.name
}
func main(){
v := student{name: "muthu", age: 22, lastName: "kumar"}
StudentDetails(v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment