概述
接口,私有struct与构造函数(真的是个函数),实现在Java中接口+类同样的功能;
package main
type SharedInformer interface {
Shard(something string) (string,error)
Informer(something string) (string,error)
}
type SharedIndexInformer interface {
SharedInformer
Indexer(something string) (string,error)
}
// NewSharedInformer creates a new instance for the listwatcher.
func NewSharedInformer(somethingShard string,somethingInformer string) SharedInformer {
return NewSharedIndexInformer(somethingShard, somethingInformer, "")
}
// NewSharedIndexInformer creates a new instance for the listwatcher.
func NewSharedIndexInformer(somethingShard string,somethingInformer string,somethingIndexer string) SharedIndexInformer {
sharedIndexInformer := &sharedIndexInformer{
somethingShard: somethingShard,
somethingInformer: somethingInformer,
somethingIndexer: somethingIndexer,
}
return sharedIndexInformer
}
type sharedIndexInformer struct {
somethingShard string
somethingInformer string
somethingIndexer string
}
func (s *sharedIndexInformer) Shard(something string) (string,error) {
return "shardSomething",nil
}
func (s *sharedIndexInformer) Informer(something string) (string,error) {
return "informSomething",nil
}
func (s *sharedIndexInformer) Indexer(something string) (string,error) {
return "indexSomething",nil
}
最后
以上就是故意果汁为你收集整理的Go # 设计模式(一)的全部内容,希望文章能够帮你解决Go # 设计模式(一)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复