Last active
January 6, 2023 04:52
-
-
Save Mayankgupta688/f349f70e3bd24cab758941dc61d2bd9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 + " " + mgr.Age; | |
} | |
func (mgr Manager) GetEmployeeSalary int { | |
return mgr.Salary | |
} | |
// Creating new Object of Type Manager | |
newManager := Manager{Name: "Mayank", Age: 30, Designation: "Developer" Salary: 10} | |
// New variable of type "Employee" created | |
var employeeInterface Employee | |
//Manager Object assigned to Interface type since Interface Contract is satisfied | |
employeeInterface = newManager | |
// Invoke Functions that belong to Interface "Employee" | |
employeeInterface.GetDetails() |
L25 misses ,
nevertheless, a great example!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
L20 misses parentheses for function