So i have this interface FrontEnd
package game
type FrontEnd interface {
PresentBoard(Board)
AwaitMove(Board) (byte, byte)
EndGame(board Board, winner Tic, moves byte)
}
I want to have many different front-ends with these three methods. For example CLIFrontEnd. My solution for this was making an empty struct and adding the methods like this:
package cli
type cliFrontEnd struct{}
func (cliFrontEnd) AwaitMove(board game.Board) (byte, byte) {
// ...
}
func (cliFrontEnd) PresentBoard(board game.Board) {
// ...
}
func (cliFrontEnd) EndGame(board game.Board, winner game.Tic, moves byte) {
// ...
}
Then a method in the cli package for creating the cli front-end:
func New() cliFrontEnd {
return cliFrontend{}
}
Is this the best way to do this? I feel like there are better ways, I don’t see the point of the empty struct for example, and is the New method how i should do it? Seemed clean so i can type cli.New()
in other packages but not sure what is the norm in go?
Add comments if anything is unclear