Introduction To Aspect Oriented Programming

Post on 15-Jul-2015

202 views 0 download

Tags:

Transcript of Introduction To Aspect Oriented Programming

Introduction To

Aspect Oriented

Programming

Present in Tabriz Software Open Talks

Saeed Shargi Ghazani

@saeed_shargi

Problem

DRY

Solutions

Some techniques include :

TemplateMetaprogramming

MetaObjectProtocol

Decorators

TemplateMethodPattern

RPC tools

Many of the Creational Patterns

MultipleInheritance and MixIns

ContextObject or ExplicitManagementOfImplicitContext

Solutions

Programming paradigm solution deal with this problem is :

Aspect Oriented Programming

History

Gregor Kiczales and colleagues at Xerox PARC in 1997

In 2001, the AspectJ extensions brought AOP to Java

IBM research team in 2001 proposed Hyper/J

Microsoft Transaction Server by EJB

Intro

Software development technique that :

Increase modularity

Managing cross cutting concerns

Infrastructure composition

Features

Cross-Cutting Concerns

Pieces of functionality that are used across multiple parts of a system

Cross-Cutting concerns and nonfunctional requirements have a lot of overlap

Advice

Code that performs the cross-cutting concerns

“What” of AOP

Pointcut

Join Point : Defined between logical steps

“Where” of AOP

Features

Tangling

When cross-cutting concern code mixed with core code

Scattering

when cross-cutting concern code used in multiple methods

Weaving

combination of core codes with aspects

Features

Features

Benefits

Clean Code

Reduce Repetition

Encapsulation

Aspects

Encapsulating

Wrapper

SRP

Decorator Pattern

OCP

Aspects Lifetime

OnStart

OnSuccess

OnExit

OnError

Types

Interceptors

IL Code Weaving

Interceptors

Calls to class methods or properties

IoC Container

No post compilation

Dynamic Proxy

Interceptors

Common use of IoC Conainer

Calling Code IoC Container

IMyInterface

MyClass :IMyInterface

Interceptors

Use of IoC Conainer with Dynamic Proxy

Calling Code IoC Container

IMyInterface

MyC

lass

:IM

yIn

terf

ac

e

Dynamic Proxy

Pro

xyIn

terc

ep

tor:

IMyIn

terf

ac

e

ProxyInterceptor:IMyInterface

IL Code Weaving

Run after compilation

Post process

IL Code Weaving

Common Tool to use :

Example

Simple example in C# with Autofac IoC Container code’s is here

SayHelloToAOP

Resources

AOP in .NET, Matthew D. Groves, Manning Publications Co, 2013

Aspect Oriented Programming in .NET, Donald Belcham, Plurarsight, 2011

http://c2.com/cgi/wiki?CrossCuttingConcern

http://en.wikipedia.org/wiki/Aspect-oriented_programming