英文:
how to see method's receiver when there are double
问题
我正在尝试理解这个例子。
Ccc方法是aaa的方法还是bbb的方法,还是aaa.bbb()的方法?
当我去GitHub上点击Ccc时,我看到了一堆定义,不知道该看哪里,非常不方便。
ans := aaa.Bbb().Ccc()
真实例子
https://github.com/CyCoreSystems/ari/blob/master/_examples/play/main.go
sub := cl.Bus().Subscribe(nil, "StasisStart")
英文:
I am trying to understand this example.
Is Ccc method of aaa OR bbb or aaa.bbb().
When I go to github, and click on Ccc, I see bunch of Definitions and it's very inconvenience not knowing where to look.
ans := aaa.Bbb().Ccc()
Real example
https://github.com/CyCoreSystems/ari/blob/master/_examples/play/main.go
sub := cl.Bus().Subscribe(nil, "StasisStart")
答案1
得分: 1
Ccc() 是 Bbb() 返回的类型的一个方法。这段代码:
ans := aaa.Bbb().Ccc()
与这段代码是等价的:
temp := aaa.Bbb()
ans := temp.Ccc()
英文:
> I am trying to understand this example. Is Ccc method of aaa OR bbb or aaa.bbb().
Ccc() is a method of whatever type Bbb() returns. This code:
ans := aaa.Bbb().Ccc()
Is the same as this code:
temp := aaa.Bbb()
ans := temp.Ccc()
答案2
得分: 1
> 真实示例 https://github.com/CyCoreSystems/ari/blob/master/_examples/play/main.go
sub := cl.Bus().Subscribe(nil, "StasisStart")
在这个示例中,
cl 是一个实现了 Client 接口的 Client 结构体,该接口具有 Bus() 方法。
Client 接口中的 Bus() 方法签名为:
Bus() Bus
因此,cl.Bus() 返回了 Bus 接口的某个实现。
Bus 接口封装了 Subscriber 接口,该接口具有以下方法:
Subscribe(key *Key, n ...string) Subscription
这就是为什么如果你手头有 Bus 接口,就可以访问 Subscribe(..) 方法。
希望我对你理解这个“真实示例”有所帮助。
英文:
> Real example https://github.com/CyCoreSystems/ari/blob/master/_examples/play/main.go
sub := cl.Bus().Subscribe(nil, "StasisStart")
In this example
cl is Client struct that implementing Client interface that has Bus() method.
Bus method signiture under Client interface is:
Bus() Bus
Therefore cl.Bus() return some implementation of Bus interface.
Bus interface is encapsulate Subscriber interface that has the following method:
Subscribe(key *Key, n ...string) Subscription
That's why you can access to Subscribe(..) method if you have Bus interface in your hands
I hope I helped to understand the "real example"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论