美文网首页
【Golang】使用工厂方法创建结构体实例

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

作者: 冉小妹Ran | 来源:发表于2020-05-13 16:38 被阅读0次
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())
}

相关文章

网友评论

      本文标题:【Golang】使用工厂方法创建结构体实例

      本文链接:https://www.haomeiwen.com/subject/hutonhtx.html