为什么我应该使用Reify而不是代理在clojure? [英] Why should I use Reify instead of proxy in clojure?

查看:107
本文介绍了为什么我应该使用Reify而不是代理在clojure?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么要在clojure中使用Reify而不是代理?

解决方案

reify 是词法闭包,可以引用周围的本地作用域。 reify proxy 不同之处在于:




  • 只支持协议或接口,没有具体的超类。

  • 方法体是结果类的真正方法,而不是外部fns。

  • 不支持在方法映射中动态交换方法。




    • 结果是在构造和调用方面比代理更好的性能。 reify 代理优先于其限制不受禁止的所有情况。



      资料来源: http://clojure.org/datatypes


      Why should I use Reify instead of proxy in clojure?

      解决方案

      The method bodies of reify are lexical closures, and can refer to the surrounding local scope. reify differs from proxy in that:

      • Only protocols or interfaces are supported, no concrete superclass.
      • The method bodies are true methods of the resulting class, not external fns.
      • Invocation of methods on the instance is direct, not using map lookup.
      • No support for dynamic swapping of methods in the method map.

      The result is better performance than proxy, both in construction and invocation. reify is preferable to proxy in all cases where its constraints are not prohibitive.

      Source: http://clojure.org/datatypes

      这篇关于为什么我应该使用Reify而不是代理在clojure?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆