Closed utterances-bot closed 2 years ago
注:本文已发布超过一年,请注意您所使用工具的相关版本是否适用
序 注意:这篇文章代码比较多,包含了 简单工厂、工厂方法、抽象工厂、DI 容器的实现,由于内容具有关联性就不进行拆分了 Go 设计模式实现,包含 23 种常见的设计模式实
https://lailin.xyz/post/factory.html
DI 容器,代码实现,第36行代码:return t.Implements(reflect.TypeOf(reflect.TypeOf((*error)(nil)).Elem())),这里为什么要用两次reflect.TypeOf方法呢?
return t.Implements(reflect.TypeOf(reflect.TypeOf((*error)(nil)).Elem()))
reflect.TypeOf
这里我的理解是,判断当前Type t的类型实现了error接口即返回true对吧?
Type t
error
true
Go设计模式02-工厂模式&DI容器 - Mohuishou
序 注意:这篇文章代码比较多,包含了 简单工厂、工厂方法、抽象工厂、DI 容器的实现,由于内容具有关联性就不进行拆分了 Go 设计模式实现,包含 23 种常见的设计模式实
https://lailin.xyz/post/factory.html