-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathembeddedinterface.go
75 lines (53 loc) · 919 Bytes
/
embeddedinterface.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
68
69
70
71
72
73
74
75
package main
type IPayment interface{
payment()
}
type ICancel interface{
cancel()
}
type ECall interface{
payment()
cancel()
}
type Booking struct {
n int
amount int
}
type Trading struct{
id int
amount int64
}
type FundTransfer struct{
payeeAccountNo int64
amount int32
}
//methods
func(b *Booking) payment(){
}
func(t *Trading) payment(){
}
func(f *FundTransfer) payment(){
}
func(b *Booking) cancel(){
}
func main() {
booking:=Booking{5,5789}
trading:=Trading{4858,450000}
fundTransfer:=FundTransfer{485824233,34000}
//runtime polymorphism
//interface 1
//var ipayment IPayment = &booking
//ipayment.payment()
var ipayment IPayment= &trading
ipayment.payment()
ipayment= &fundTransfer
ipayment.payment()
//interface 2
// var icancel ICancel=&booking
// icancel.cancel()
//embedding
//interface 3
var ecall ECall=&booking
ecall.payment()
ecall.cancel()
}