Tuesday, April 26, 2011

Need for AOP

Aspect-Oriented Programming (AOP) complements Object-Oriented Programming (OOP) by providing another way of thinking about program structure. 

Consider a following method code (say in a webservice method):

   //start new session
   //some business logic
   //commit transaction
}catch(Exception ex)
   //handle exception
   //close session
//return the output

So like this method above, there will be lots of other methods similar to this....But don't you think it will be nice if  we only deal with business logic, rather than writing the repeatative code like handling exceptions, logging,security management, etc. These code tidbits are called concerns or aspects or advices (though described below). These are used interchangeably, though there are slight differences, which we will see in course of time.

So this is where AOP comes into picture. We can simply write our code as a simple business logic, without dealing with above mentioned concerns or repeatative code. For eg. for security checks, you can add the authorization into the execution path with a type of IOC implementation called AOP or aspect oriented programming. 

See Aop introduction

No comments:

Post a Comment