This file contains 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
// Player represents a player in a game. | |
type Player struct { | |
ID uint32 | |
Handle, Name, Country string | |
Games []string | |
} | |
var ( | |
playerIDMap = make(map[uint32]Player) | |
playerHandleMap = make(map[string]uint32) // ref: playerIDMap |
This file contains 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
type foobar interface { | |
foo() | |
bar() | |
} | |
type itemA struct{} | |
func (a *itemA) foo() { | |
fmt.Println("foo on A") | |
} |
This file contains 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
type student interface { | |
register(context.Context, string, string, int) | |
enrollCourse(uint32, time.Time) error | |
pass(uint32) error | |
fail(uint32) error | |
} | |
type alsoStudent interface { | |
register(ctx context.Context, name, profession string, age int) | |
enrollCourse(courseID uint32, start time.Time) error |
This file contains 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
public interface Vehicle { | |
public void start(); | |
public void stop(); | |
} | |
public class Car implements Vehicle { | |
public void start() { | |
System.out.println("starting engine..."); | |
} | |
public void stop() { |
This file contains 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
type Vehicle interface { | |
Start() | |
Stop() | |
} | |
type Car struct {} | |
func (c *Car) Start() { | |
fmt.Println("starting engine...") | |
} |
This file contains 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
type toaster interface { | |
toast() | |
} | |
type acmeToaster struct {} | |
func (a *acmeToaster) toast() { fmt.Println("Commencing toasting of bread...") } | |
func doToast(t toaster) { | |
t.toast() |
This file contains 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
// Verify that acmeToaster satisfies interface toaster. | |
var _ toaster = &acmeToaster{} |
This file contains 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
type empty interface {} |
This file contains 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
type monster struct { | |
damage int | |
} | |
func (m *monster) attack() int { | |
return m.damage | |
} | |
type attacker interface { | |
attack() int |
This file contains 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
type toaster interface { | |
toast() | |
} | |
type acmeToaster struct {} | |
func (a *acmeToaster) toast() { fmt.Println("Commencing toasting of bread...") } |
NewerOlder