AOP基础 [英] AOP Fundamentals

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

问题描述

面向切面编程是我很难找到任何好的信息的主题.我的旧软件工程教科书只简要地(含糊地)提到了它,维基百科和我能够在上面找到的各种其他教程/文章给出了关于它是什么、如何使用的超学术、高度抽象的定义它,以及何时使用它.定义我似乎不明白.

Aspect-oriented programming is a subject matter that has been very difficult for me to find any good information on. My old Software Engineering textbook only mentions it briefly (and vaguely), and the wikipedia and various other tutorials/articles I've been able to find on it give ultra-academic, highly-abstracted definitions of just what it is, how to use it, and when to use it. Definitions I just don't seem to understand.

我对 AOP 的(非常差的)理解是,生成高质量软件系统的许多方面都无法完美地装入一个漂亮的小内聚包中.某些类,例如 Loggers、Validators、DatabaseQueries 等,将在您的整个代码库中使用,因此将是高度耦合的.我(同样,非常)对 AOP 的理解是,它关注如何处理这些类型的通用耦合"包的最佳实践.

My (very poor) understanding of AOP is that there are many aspects of producing a high-quality software system that don't fit neatly into a nice little cohesive package. Some classes, such as Loggers, Validators, DatabaseQueries, etc., will be used all over your codebase and thus will be highly-coupled. My (again, very poor) understanding of AOP is that it is concerned with the best practices of how to handle these types of "universally-coupled" packages.

问题:这是真的,还是我完全不知道?如果我完全错了,有人可以对 AOP 是什么给出一个简洁的外行解释,一个所谓的方面的例子,甚至可能提供一个简单的代码示例?

Question : Is this true, or am I totally off? If I'm completely wrong, can someone please give a concise, laymen explanation for what AOP is, an example of a so-called aspect, and perhaps even provide a simple code example?

推荐答案

关注点分离是软件开发的基本原则,David Parnas 有一篇经典论文 关于将系统分解为模块的标准 可能会向您介绍该主题并阅读鲍勃叔叔的可靠原则.

Separation of Concerns is a fundamental principle in software development, there is a classic paper by David Parnas On the Criteria To Be Used in Decomposing Systems into Modules that may introduce you to the subject and also read Uncle Bob's SOLID Principles.

但是,在许多用例中可能包含横切问题,例如身份验证、授权、验证、日志记录、事务处理、异常处理、缓存等,这些问题会产生软件中的所有层.如果你想不重复地解决问题并采用 DRY 原则,你必须以复杂的方式处理它.

But then there are Cross Cutting concerns that might be included in many use cases like authentication, authorization, validation, logging, transaction handling, exception handling, caching, etc that spawn all the layers in software. And if you want to tackle the problem without duplication and employing the DRY principle, you must handle it in a sophisticated way.

您必须使用声明式编程,在 .net 中可以简单地通过属性注释方法或属性,然后发生的事情是根据这些注释在运行时更改代码的行为.

You must use declarative programming, that simply in .net could be annotating a method or a property by an attribute and what happened later is changing the behavior of code in runtime depending of those annotations.

您可以在 萨默维尔的软件工程书籍

有用的链接C2 wiki CrossCuttingConcernMSDN如何解决面向方面的软件开发中的横切关注点

这篇关于AOP基础的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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