-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembedded_interfaces.go
62 lines (50 loc) · 982 Bytes
/
embedded_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
package main
import "fmt"
// Interface 1
type BankDetails interface {
details()
}
// Interface 2
type BankPartners interface {
partners()
}
// Interface 3
// Interface 3 embedded with
// interface 1 and 2
type FinalDetails interface {
BankDetails
BankPartners
}
// Structure
type bank struct {
name string
branch string
partner string
}
// Implementing method of
// the interface 1
func (a bank) details() {
fmt.Print("Bank Name: ", a.name)
fmt.Print("\nBranch: ", a.branch)
}
// Implementing method
// of the interface 2
func (a bank) partners() {
fmt.Print("\nPartner: ", a.partner)
}
// Main value
func main() {
// Assigning values
// to the structure
values := bank{
name: "IDFC First Bank",
branch: "Akola",
partner: "Gaurav",
}
// Accessing the methods of
// the interface 1 and 2
// Using FinalDetails interface
var f FinalDetails = values
f.details()
f.partners()
}