我正在尝试为类型参数设计模式实现指针方法示例的变体,以便抽象一些统一的存储库接口。
我的印象是该Person结构将继承Entityif it composes的方法集*Entity,但我收到如下编译时错误。有人可以解释为什么不满足类型约束以及如何修复此代码吗?
为糟糕的标题道歉;如果有人可以提出改进的摘要,那就太棒了(我对 Go 还很陌生)。
谢谢 :)
package main
// domain
type PEntity[E any] interface {
*E
SetID(id string)
}
type Entity struct {
ID string
}
func (e Entity) SetID(id string) {
e.ID = id
}
type Repository[E Entity, PE PEntity[E]] interface {
Get(id string) *E
}
// data
type Person struct {
*Entity
}
type PersonRepository interface {
Repository[Person, *Person] // -> Person does not implement Entity
AddPet(name string)
// ...
}
暮色呼如
相关分类