Spring Framework

Spring Projects

Spring Project 1

AOP (Aspect Oriented Programming)
Previous Home Next

Introduction: An Aspect Oriented Programming (AOP) is a programming model that compliments object oriented programming model and provides an efficient mechanism of implementing behaviors which have crosscutting concerns.

Terminology of AOP

There are following terminology of AOP (Aspect Oriented Programming) in spring framework:

  1. Concerns: A concerns represent a task i.e performed as part of an operation. A concerns is set to be crosscutting concerns is it participate of multiple operation.

  2. Advice: Implementation of a concerns is called Advice.

  3. Joinpoint: Joinpoint represent easily identifiable intersection point in the execution of an application where Advices can be inserted. Loading of classes, creation of an object, invocation of method etc. can be used as joinpoint. A spring AOP implementation only support method invocation joinpoint.

  4. Pointcut: A pointcut is a collection of Joinpoint.

  5. Aspect: An Aspect is a collection of Pointcut and Advices.

Crosscutting concern in Spring AOP

A concern represent a task that is performed as part of an operation. A concern is set to be crosscutting is it participate of multiple operation.

Concerns can be divided in to multiple category such as:

  1. Implementation Concern
  2. Business Concern
  3. Organization Concern etc.

Implementation Concern: Implementation Concerns represents those task which are required before implementing for example:-Validation, Authorization, etc

Business Concern: Business concern represent actual logic or main task of an operation.

Organization Concern: Organization concern represent additional services, facility and requirement associated an operation by an organization.

Weaving in Spring AOP

The process of inserting advices is called weaving. Different AOP framework supports either weaving types:

  1. Compilation time weaving
  2. Runtime weaving

Compilation time Weaving:

In Compilation time weaving advices are inserted at the time of Compilation at the special AOP compiler.

Advantage: The major advantage of this approach are performance.

Disadvantage: Special AOP compiler are required and application need to be recompile.

Runtime Weaving:

In this approach advices are dynamically inserted which the help of proxy object.

Advantage: Special AOP compiler are not required and Application are not required to be modified or recompile each time . Number of concerns or order changed.

Disadvantage: Performance are degrade because of additional overhead are proxy.

Note: A Spring AOP support Runtime weaving.

Previous Home Next