【Golang】使用工厂方法创建结构体实例

2020-05-13  本文已影响0人  冉小妹Ran
package main

import "fmt"

type Client interface {
    Method() string
}

type client struct{}

func (c *client) Method() string {
    return "client.Method"
}

func NewClient() Client {
    return &client{}
}

func main() {
    c := NewClient()
    fmt.Println(c.Method())
}

上一篇 下一篇

猜你喜欢

热点阅读