-
Notifications
You must be signed in to change notification settings - Fork 1
/
interface.go
67 lines (63 loc) · 1.26 KB
/
interface.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
package main
import(
"fmt"
)
//type empty interface{}
//type USB interface{
// Name() string
// Connect()
//}
//type Connecter interface{
// Connect()
//}
//type PhoneConnecter struct{
// name string
//}
//func (pc PhoneConnecter) Name() string{
// return pc.name
//}
//func (pc PhoneConnecter) Connect(){
// fmt.Println("Connectd:",pc.name)
//}
//func main(){
// a := PhoneConnecter{"PhoneConnecter"}
// a.Connect()//Connectd: PhoneConnecter
// Disconnect(a)
//}
//func Disconnect(usb USB){
// if pc,ok := usb.(PhoneConnecter);ok {
// fmt.Println("Disconnected" ,pc.name)//Disconnected PhoneConnecter
// return
// }
// fmt.Print("Disconnected.")//Disconnected.
//}
//type empty interface{}
//type USB interface{
// Name() string
// Connect()
//}
//type Connecter interface{
// Connect()
//}
//type PhoneConnecter struct{
// name string
//}
//func (pc PhoneConnecter) Name() string{
// return pc.name
//}
//func (pc PhoneConnecter) Connect(){
// fmt.Println("Connectd:",pc.name)
//}
//func main(){
// a := PhoneConnecter{"PhoneConnecter"}
// a.Connect()//Connectd: PhoneConnecter
// Disconnect(a)
//}
//func Disconnect(usb interface{}){
// switch v:=usb.(type){
// case PhoneConnecter:
// fmt.Println("Disconnected" ,v.name)
// default:
// fmt.Print("Unknown decive")
// }
//}