Created
August 2, 2020 01:25
-
-
Save luandevpro/c885cec347e9f75db833eda3a6606c54 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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