-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path11_multiple_interfaces.go
67 lines (54 loc) · 1.33 KB
/
11_multiple_interfaces.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Čtvrtá část
// Rozhraní, metody, gorutiny a kanály v programovacím jazyku Go
// https://www.root.cz/clanky/rozhrani-metody-gorutiny-a-kanaly-v-programovacim-jazyku-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů ze čtvrté části:
// https://github.com/tisnik/go-root/blob/master/article_04/README.md
//
// Demonstrační příklad číslo 11:
// Typ implementující dvě rozhraní.
//
// Dokumentace ve stylu "literate programming":
// https://tisnik.github.io/go-root/article_04/11_multiple_interfaces.html
package main
import "fmt"
// Interface1 je exportované rozhraní s jedinou metodou
type Interface1 interface {
method1()
}
// Interface2 je exportované rozhraní s jedinou metodou
type Interface2 interface {
method2()
}
// Type je uživatelsky definovaný datový typ
type Type struct{}
func (Type) method1() {
fmt.Println("Type.method1")
}
func (Type) method2() {
fmt.Println("Type.method2")
}
func f1(i Interface1) {
fmt.Println("Interface1.f1")
i.method1()
}
func f2(i Interface2) {
fmt.Println("Interface2.f2")
i.method2()
}
func main() {
t := Type{}
t.method1()
t.method2()
fmt.Println()
f1(t)
fmt.Println()
f2(t)
fmt.Println()
}