I'm new on go; have two files that share similar behavior and was told to use composition to avoid having duplicated code, but can't quite understand the concept of composition.
Both files have common functionality but have their differences one of another.
player1.go
package game
type confPlayer1 interface {
Set(string, int) bool
Move(string) bool
Initialize() bool
}
func Play(conf confPlayer1) string {
// code for Player1
}
// ... other funcs
player2.go
package game
type confPlayer2 interface {
Set(string, int) bool
Move(string) bool
// Initializer is only for Player1
}
func Play(conf confPlayer2) string {
// code for Player2, not the same as Player1.
}
// ... the same other funcs from player1.go file
// ... they differ slighly from player1.go funcs
Is there a way to combine all into a single player.go file?