mohuishou / blogComment

mohuishou's blog comment
0 stars 0 forks source link

post/factory #281

Closed utterances-bot closed 2 years ago

utterances-bot commented 2 years ago

Go设计模式02-工厂模式&DI容器 - Mohuishou

        注:本文已发布超过一年,请注意您所使用工具的相关版本是否适用

序 注意:这篇文章代码比较多,包含了 简单工厂、工厂方法、抽象工厂、DI 容器的实现,由于内容具有关联性就不进行拆分了 Go 设计模式实现,包含 23 种常见的设计模式实

https://lailin.xyz/post/factory.html

my4tb commented 2 years ago

DI 容器,代码实现,第36行代码:return t.Implements(reflect.TypeOf(reflect.TypeOf((*error)(nil)).Elem())),这里为什么要用两次reflect.TypeOf方法呢?

这里我的理解是,判断当前Type t的类型实现了error接口即返回true对吧?