Skip to content

Instantly share code, notes, and snippets.

@Mayankgupta688
Last active January 6, 2023 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mayankgupta688/f349f70e3bd24cab758941dc61d2bd9e to your computer and use it in GitHub Desktop.
Save Mayankgupta688/f349f70e3bd24cab758941dc61d2bd9e to your computer and use it in GitHub Desktop.
// 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()
@vigneshv-brl
Copy link

L20 misses parentheses for function

@vigneshv-brl
Copy link

L25 misses ,
nevertheless, a great example!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment