1.Topics‎ > ‎Architecture‎ > ‎Patterns‎ > ‎d.Programming Patterns‎ > ‎

Aspect Oriented Programming (AOP)

  1. Overview
    1. The Aspect: Aspect is usually  non functional functional requirement of system such as logging , security , monitoring etc.
    2. Type of Aspects
      1. Crosscutting Aspect
        1. Authentication
        2. Authorization
        3. Caching
        4. Communication
        5. Configuration Management
        6. Exception Management
        7. Logging and Instrumentation
        8. State Management
        9. Validation
      2. Code Repetition (DRY) Aspect
      3. Code Generation Aspect
    3. Aspect Oriented Programming 
      1. It is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting (Non Functional Requirements) concerns.
      2. Core objective is to increase code reuse that are not possible by conventional OOPS techniques.
      3. It helps to implement DRY Principle in more advance way beyond the capabilities of OOPS.
      4. There are several frameworks that facilitates to AOP, for example WCF exposes several hooks (extention points) that we can leverage for the purpose of attaching aspects like logging.
      5. AOP is a specific case of meta-programming.
  2. Getting Started With AOP
    1. http://www.codeproject.com/Articles/11385/Aspect-Oriented-Programming-in-NET
    2. http://www.springframework.net/doc-latest/reference/html/aop.html
    3. http://weblogs.asp.net/podwysocki/archive/2008/03/28/understanding-aop-in-net.aspx
    4. http://www.postsharp.net/aop.net
  3. AOP Implementation Approaches
    1. AOP implementations are technically interceptors and can be implemented using two fundamental approaches.
    2. Proxy/Decorator Based
      1. Uses some short of decorator /proxy (Dynamic Proxy) combination to achieve the goal.
      2. Easy to implement and no post compilation steps required.
      3. Implementation is based on common interface requirement that restrict the uses scenario.
      4. But advantage is that No Post Compilation steps are required.
      5. Useful for limited number of classes and methods.
      6. Most of the time implementation (Proxy/decorator) is achive via some IOC Containers.
    3. Post Compilation (Instrumentation) Based
      1. Uses IL Weaving to achieve the goal.
      2. Support very complex scenarios and aspects.
      3. Needs Post Compilation steps.
      4. Can suport large number of classes and meathod.
  4. Weaving Approachs
  5. There are basically two approaches to change the behavior of a program in .NET (i.e. to weave a .NET program):
    Compile-Time Weaving: the program is modified during the build process on the development machine, before deployment.
    Runtime Weaving: the program is modified during its execution, after deployment.
  6. Popular AOP Frameworks(Dot.Net)
    1. Post Shorp (Top Rated)
    2. Unity (Enterprise Library)
    3. Spring.Net
    4. Casel Windser
    5. NInject
  7. Comparison of AOP frameworks 
    1. Compare PostSharp with other implementations of AOP
    2. Code Project:Rating-of-Open-Source-AOP-Frameworks-in-NET
    3. http://csharp-source.net/open-source/aspect-oriented-frameworks
  8. Specific Considerations 
    1. AOP Vs Decorator Vs Proxy : AOP usually uses decorators and dynamic proxy to implement achieve it`s goal
    2. AOP and Dynamic Proxy:  AOP usually uses decorators and dynamic proxy to implement achieve it`s goal
    3. AOP Vs Interceptors : Backbone of AOP is Interceptors.
    4. Interceptor Vs Proxy : Interceptors can use proxy patterns as implementation technique.
    5. Interceptor Vs Decorator :  Interceptors can use decorators patterns as implementation technique that in turn may further use proxy for implementation.
    6. Decorator Vs Proxy : Technically decorator is a series of chained proxies that are defined at compile time and loaded at run time. 
    7. AOP Vs AOD 
      1. AOP includes programming methods and tools that support the modularization of concerns at the level of the source code,
      2. "aspect-oriented software development" refers to a whole engineering discipline.
    8. AOP and DI:Several AOP implementation technique uses DI for attaching aspect to target objects.
    9. Dynamic Proxy Vs Transparent Proxy : Transparent Proxy is a kind of Instance Proxy Generated dynamically (i.e. Dynamic Proxy) that is mainly used as interception technique by Unity Framework. 
  9. AOP Books
    1. Aspectj in Action: Practical Aspect-Oriented Programming : Though this book is in JAVA but explains fundamentals very well. 
    2. AOP in .NET: Practical Aspect-Oriented Programming :Explains AOP implementation in Dot.Net, most implementation is based on PostSharp
  10. References 
    1. http://www.postsharp.net/aop.net
    2. http://www.springframework.net/doc-latest/reference/html/aop.html
    3. http://www.codeproject.com/Articles/11385/Aspect-Oriented-Programming-in-NET