Skip to content

Instantly share code, notes, and snippets.

@luandevpro
Created August 2, 2020 01:25
Show Gist options
  • Select an option

  • Save luandevpro/c885cec347e9f75db833eda3a6606c54 to your computer and use it in GitHub Desktop.

Select an option

Save luandevpro/c885cec347e9f75db833eda3a6606c54 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type SalaryCalculator interface {
salaryCalculator() int
}
type Permanent struct {
id int
basic int
pf int
}
type Contract struct {
id int
basic int
}
func (p Permanent) salaryCalculator() int {
return p.basic + p.pf
}
func (c Contract) salaryCalculator() int {
return c.basic
}
func totalEx(s []SalaryCalculator) int {
ex := 0
for _, v := range s {
ex = ex + v.salaryCalculator()
}
return ex
}
func main() {
per1 := Permanent{1, 600, 100}
per2 := Permanent{2, 600, 50}
con1 := Contract{3, 300}
total := []SalaryCalculator{per1, per2, con1}
fmt.Println(totalEx(total))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment