Display the salary using interface in Go

Basically interface defines the behaviour of an object. We are calculating the total amount of full time employee and part time employee salary. Full time employee has basic pay and pf. Contract employee has basic pay.

package main

import (  
    "fmt"
)

type SalaryCalculator interface {  
    CalculateSalary() int
}

type Permanent struct {  
    empId    int
    basicpay int
    pf       int
}

type Contract struct {  
    empId  int
    basicpay int
}

func (p Permanent) CalculateSalary() int {  
    return p.basicpay + p.pf
}

func (c Contract) CalculateSalary() int {  
    return c.basicpay
}


func calSalary(s []SalaryCalculator) {  
    sum := 0
    for _, v := range s {
        sum = expense + v.CalculateSalary()
    }
    fmt.Printf("Total Expense Per Month in dollar %d", sum)
}

func main() {  
    permanent := Permanent{1, 5000, 20}
    contract := Contract{3, 3000}
    employees := []SalaryCalculator{permanent, contract}
    calSalary(employees)

}



Output :
Total Expense Per Month in dollar 8020