@kjk1/

gobook oo interface polymorhism

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.395531125647272","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgKAoJImZtdCIKKQoKdHlwZSBSdW5uZXIgaW50ZXJmYWNlIHsKCVJ1bigpCn0KCnR5cGUgQWRtaW4gc3RydWN0IHsKCVVzZXJuYW1lLCBQYXNzd29yZCBzdHJpbmcKfQoKZnVuYyAoYWRtaW4gQWRtaW4pIFJ1bigpIHsKCWZtdC5QcmludGxuKCJBZG1pbiA9PT4gUnVuKCkiKQp9Cgp0eXBlIFVzZXIgc3RydWN0IHsKCUlEICAgICAgICAgICAgICB1aW50NjQKCUZ1bGxOYW1lLCBFbWFpbCBzdHJpbmcKfQoKZnVuYyAodXNlciBVc2VyKSBSdW4oKSB7CglmbXQuUHJpbnRsbigiVXNlciA9PT4gUnVuKCkiKQp9CgovLyBSdW5uZXJFeGFtcGxlIHRha2VzIGFueSB0eXBlIHRoYXQgZnVsbGZpbHMgdGhlIFJ1bm5lciBpbnRlcmZhY2UKZnVuYyBSdW5uZXJFeGFtcGxlKHIgUnVubmVyKSB7CglyLlJ1bigpCn0KCmZ1bmMgbWFpbigpIHsKCWFkbWluIDo9IEFkbWluewoJCSJ6b2xhIiwKCQkic3VwZXJzZWNyZXRwYXNzd29yZCIsCgl9CgoJdXNlciA6PSBVc2VyewoJCTEsCgkJIlplbGFsZW0gTWVrb25lbiIsCgkJInpvbGEubWsuMjdAZ21haWwuY29tIiwKCX0KCglSdW5uZXJFeGFtcGxlKGFkbWluKQoKCVJ1bm5lckV4YW1wbGUodXNlcikKfQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main

import (
	"fmt"
)

type Runner interface {
	Run()
}

type Admin struct {
	Username, Password string
}

func (admin Admin) Run() {
	fmt.Println("Admin ==> Run()")
}

type User struct {
	ID              uint64
	FullName, Email string
}

func (user User) Run() {
	fmt.Println("User ==> Run()")
}

// RunnerExample takes any type that fullfils the Runner interface
func RunnerExample(r Runner) {
	r.Run()
}

func main() {
	admin := Admin{
		"zola",
		"supersecretpassword",
	}

	user := User{
		1,
		"Zelalem Mekonen",
		"[email protected]",
	}

	RunnerExample(admin)

	RunnerExample(user)
}