Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- )
- type User struct {
- Name string
- }
- func (u *User) sayName(speaker string) bool {
- fmt.Printf("Hello %s, my name is %s\n", speaker, u.Name)
- return true
- }
- type Role interface {
- unlockGate() bool
- }
- type Admin struct {
- *User
- roleType string
- SecretPassword string
- entries int32
- }
- // A method needed by the Role interface.
- func (a *Admin) unlockGate() bool {
- a.entries++
- fmt.Printf("unlocking gate as %s\n", a.Name)
- return true
- }
- // A function that works on any Role.
- func unlock(r Role) {
- r.unlockGate()
- }
- func main() {
- b := &Admin{&User{"Pancho"}, "administrator", "pa$$word", 0}
- b.sayName("Roberto")
- b.unlockGate()
- unlock(b)
- fmt.Printf("Total entries %d\n", b.entries)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement