-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoly.go
41 lines (30 loc) · 924 Bytes
/
poly.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
package main
import "fmt"
// Creating a Simple Interface "Employee"
type Employee interface {
GetDetails() string
GetEmployeeSalary() int
}
// Creating a new type "Manager" containing all functions required by "Employee" Interface
type Manager struct {
Name string
Age int
Designation string
Salary int
}
func (mgr Manager) GetDetails() string {
return mgr.Name
}
func (mgr Manager) GetEmployeeSalary() int {
return mgr.Salary
}
func main() {
// Creating new Object of Type Manager
newManager := Manager{Name: "Mayank", Age: 30, Designation: "Developer", Salary: 10}
GetDetails(newManager)
var employeeInterface Employee
//Manager Object assigned to Interface type since Interface Contract is satisfied
employeeInterface = newManager
// Invoke Functions that belong to Interface "Employee"
fmt.Println(employeeInterface.GetDetails())
}