Skip to content

Instantly share code, notes, and snippets.

@didi1246888
Created March 11, 2022 02:05
Show Gist options
  • Save didi1246888/30e381057b6aa2cb9f40c249a889f505 to your computer and use it in GitHub Desktop.
Save didi1246888/30e381057b6aa2cb9f40c249a889f505 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type Person struct { // abstract field
name string
}
func (person *Person) setName(name string) { // Encapsulation method
person.name = name
}
func (person *Person) GetInfo() { // Encapsulation method
fmt.Println(person.name)
}
func main() {
p := Person{"night guard"}
p.setName("sam")
p.GetInfo() // output new name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment