mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-23 04:16:02 +03:00
28 lines
333 B
Go
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()
|
||
|
}
|