go-pattern-examples/creation/01_new/new_test.go
2020-05-02 17:36:50 +08:00

28 lines
333 B
Go

package newpattern
import (
"fmt"
"testing"
)
type homecat interface {
sleep()
}
type blackCat struct {
name string
}
func newBlackCat(name string) homecat{
return &blackCat{name}
}
func (b blackCat) sleep() {
fmt.Print( b.name + " is sleeping")
}
func TestNewMode(t *testing.T){
cat := newBlackCat("pi")
cat.sleep()
}