什么是面向方面编程? [英] What is Aspect Oriented Programming?

查看:29
本文介绍了什么是面向方面编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是面向方面的编程?

每次我在这里观看播客或阅读有关它的博客文章时,即使是在这里,它们也听起来像是弦理论之类的东西.用类固醇的依赖注入来描述它的最佳方式是 OOP 吗?

Every time I here a podcast or read a blog entry about it, even here, they make it sound like string theory or something. Is the best way to describe it OOP with Dependency Injection on steroids?

每次有人试图解释它时,它就像,Aspects、[Adults from Peanuts Cartoon sound]、正交、[更多噪音]、横切关注点等.说真的,任何人都可以用外行的术语来描述它.

Every time someone tries to explain it, it’s like, Aspects, [Adults from Peanuts Cartoon sound], Orthogonal, [more noise], cross cutting concerns, etc. Seriously, can anyone describe it in layman’s terms.

推荐答案

外行术语让我举个例子.假设您有一个 Web 应用程序,并且您需要添加错误日志记录/审计.一种实现是进入每个公共方法并添加您的 try catch 块等...

Laymans terms so let me give you an example. Let's say you have a web application, and you need to add error logging / auditing. One implementation would be to go into every public method and add your try catch blocks etc...

面向方面的说法是胡说八道,让我在你的方法周围注入我的方法,例如,系统可能会调用,而不是调用 YourClass.UpdateModel(),

Well Aspect oriented says hogwash with that, let me inject my method around your method so for example instead of calling YourClass.UpdateModel(), the system might call,

LoggingHandler.CallMethod() 然后,此方法可能会将调用重定向到 UpdateModel,但会将其包装在 try catch 块中以处理日志记录错误.

LoggingHandler.CallMethod() this method might then redirect the call to UpdateModel but wraps it in a try catch block to handle logging errors.

现在的诀窍是这种重定向会自动发生,通过配置或将属性应用于方法.

Now the trick is that this redirection happens automagically, through configuration or by applying attributes to methods.

这适用于您所说的横切事物,这些事物是每个域中都存在的非常常见的编程元素,例如:日志记录、审计、事务管理、授权.

This works for as you said cross cutting things which are very common programing elements that exist in every domain, such as: Logging, Auditing, Transaction Mgmt, Authorization.

其背后的想法是从您的业务/应用层中删除所有这些常见的管道代码,以便您可以专注于解决问题,而不必担心记录此方法调用或该方法调用.

The idea behind it is to remove all this common plumbing code out of your business / app tier so you can focus on solving the problem not worrying about logging this method call or that method call.

这篇关于什么是面向方面编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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