什么是AOP?
AOP是面向切面编程,全称 Aspect-Oriented-Programming。它能够让我们在不影响原有功能的前提下为软件横向拓展功能。
什么是横向拓展?
web开发为 Controller -> Service -> Dao,此结构为纵向,具体的某一层则为横向。AOP可以作用于某横向模块中的所有方法。
AOP 主要解决的问题:
- 代码分散问题,特别是那些非功能性代码。
- 面向对象编程思维的一种补充和完善。
AOP与OOP的区别
AOP是OOP的补充。AOP可以解决当需要为多个对象引入一个公共行为(如操作记录、日志等)而导致程序产生的大量重复代码问题。
核心知识点
- 连接点: join point,程序的执行点,如类方法、类方法里的代码块。
- 切入点:point cut,捕获「连接点」的代码结构(定义一个代码逻辑来捕获某个连接点的代码)
- 方面:aspect,具体被执行切面逻辑代码,类似 一个类。
- 通知:advice,「切入点」执行的代码,定义了 在「连接点」什么时机来执行 「方面」。
运用场景
- 非功能性需求,日志、事务、操作记录
- 功能性需求
以上参考:https://mp.weixin.qq.com/s/0-JT7wooyDgZ9bOHVhATLg、https://mp.weixin.qq.com/s/iUeOfykcAOnkervlFwnyEw