AOP 如何帮助数据绑定?
我最近读了一篇有趣的文章关于 Anders Hejlsberg 反对 AOP 的论点的博客文章。
第一个反反论证提到了数据绑定:
神话 1。“面向方面的编程对于代码的调试和检测很有趣,但它并不是一个成熟的编程学科。”
真相 1。安德斯可能停在“Hello, world”的例子上。
尽管代码插装无疑是 AOP 的一个重要用例(并且您会在每个“入门”文档中看到该用例),但该技术在实现任何重要的现实生活中时显着简化了开发人员的工作应用。仅举几个 AOP 真正有帮助的现实场景:
* Data Binding (INotifyPropertyChanged)
我正在尝试考虑如何在数据绑定场景中使用 AOP。我一直认为绑定依赖于反射来发挥它的“魔力”。我非常确定绑定场景中所需的一切都可以通过反射获得。 AOP 是否用于(轻微)性能提升?
I recently read an interesting blog post on Anders Hejlsberg's arguments against AOP.
The first anti-anti argument mentions data binding:
Myth 1. “Aspect-oriented programming is interesting for debugging and instrumentation of code and is not a full-fledged programming discipline.”
Truth 1. Anders probably stopped at the “Hello, world” example.
Although code instrumentation is certainly an important use case of AOP – and the one you would see in every “getting started” documentation – the technology significantly simplifies the work of developers when it comes to implement any non-trivial, real-life application. Just to cite a few real-life scenarios where AOP really helps:
* Data Binding (INotifyPropertyChanged)
I'm trying to think of how AOP is used in a data binding scenario. I always assumed that binding relied on reflection to do it's "magic." I'm pretty sure everything you need in a binding scenario is available via reflection. Is AOP being used for a (slight) performance boost?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
他指的不是数据绑定,而是 AOP 真正大放异彩的
INotifyPropertyChanged
(以及类似的)部分。目前,当一个类实现 INotifyPropertyChanged 时,属性看起来像这样:
在适当的 AOP 中,它们可能看起来像这样
造成很大的可读性差异,特别是当几个属性的设置器在其中有一些实际规则时它。
即使使用通用基类、表达式、反射和一些棘手的实现,您所希望的最好结果是:
即使这样可读性也较差(并且性能也较差)
It's not the databinding he's referring to, but the
INotifyPropertyChanged
(and similar) part that AOP would really shine.Currently, when a class implements
INotifyPropertyChanged
, properties look like this:Where with decent AOP, they could look like this
Makes a big readability difference, especially when the setter for a couple properties has a few actual rules in it.
Even with generic base classes, Expressions, Reflection, and some tricky implementations, the best you hope for is:
And even that's not as readable (and is less performant as well)