AOP基础知识 [英] AOP Fundamentals

查看:77
本文介绍了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是什么,所谓的 aspect 的示例,甚至可以提供一个简单的代码示例?

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有一篇经典论文鲍伯叔叔的SOLID原则.

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 CrossCuttingConcern 如何解决面向方面的软件开发中的横切关注点

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

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