知识卡片

结构图卡 · 4545.g.8.q.5.c · 生成模型:GPT-6

函数值适配单方法依赖

理解等级:中级

BlindAlerterFunc的底层类型是func(time.Duration,int),它再定义同签名业务方法,并在方法中调用自身函数。这样闭包或StdOutAlerter可转为BlindAlerter,调用方无需新造空struct。适配保留接口的调度责任,并不凭空添加取消、错误或完成等待能力。

结构图:

类图

classDiagram
 class BlindAlerter {<<interface>>
 +ScheduleAlertAt(duration time.Duration, amount int)
 }
 class BlindAlerterFunc {<<functionType>>
 +ScheduleAlertAt(duration time.Duration, amount int)
 }
 BlindAlerter <|.. BlindAlerterFunc : 隐式实现
 note for BlindAlerterFunc "底层签名 func(time.Duration, int),方法调用函数值自身"
这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    • 主要讲解 · Time

    原书出处 · 1 处

    • Time · 查看原书依据

      ation time.Duration, amount int) } type BlindAlerterFunc func(duration time.Duration, amount int) func (a BlindAlerterFunc) ScheduleAlertAt(duration t

    参考来源

    - 位置:《通过测试学习 Go 编程》Time,spine027(book-sources;extracted/通过测试学习 Go 编程/_epub-src/OEBPS/Text/26.html)。 - 结论依据:原文以函数类型实现ScheduleAlertAt,再把StdOutAlerter注入main。 - 原始内容:ation time.Duration, amount int) } type BlindAlerterFunc func(duration time.Duration, amount int) func (a BlindAlerterFunc) ScheduleAlertAt(duration t