Ruby中的委托是什么?

Ruby中的委托是什么?,第1张

概述我在教科书中遇到过这个问题,但我甚至不知道代表团是什么.我知道包含是什么,但不知道代表团是什么. In the context of Ruby, compare delegation to module inclusion in terms of the notion of class interfaces. With module inclusion, methods defined in mo 我在教科书中遇到过这个问题,但我甚至不知道代表团是什么.我知道包含是什么,但不知道代表团是什么.

In the context of Ruby,compare delegation to module inclusion in
terms of the notion of class interfaces.

With module inclusion,methods defined in modules become part of the
interface of classes(and all their subclasses). This is not the case
with delegations.

你能用外行的话解释一下吗?

解决方法 简单地说,委托就是当一个对象使用另一个对象进行方法调用时.

如果您有这样的事情:

class A  def foo    puts "foo"  endendclass B  def initialize    @a = A.new  end  def bar    puts "bar"  end  def foo    @a.foo  endend

当调用foo方法时,B类的一个实例将使用A类的foo方法.换句话说,B的实例将foo方法委托给A类.

总结

以上是内存溢出为你收集整理的Ruby中的委托是什么?全部内容,希望文章能够帮你解决Ruby中的委托是什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1232699.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-06
下一篇2022-06-06

发表评论

登录后才能评论

评论列表(0条)

    保存