Introduction To Aspect Oriented Programming

22
Introduction To Aspect Oriented Programming Present in Tabriz Software Open Talks Saeed Shargi Ghazani @saeed_shargi

Transcript of Introduction To Aspect Oriented Programming

Page 1: Introduction To Aspect Oriented Programming

Introduction To

Aspect Oriented

Programming

Present in Tabriz Software Open Talks

Saeed Shargi Ghazani

@saeed_shargi

Page 2: Introduction To Aspect Oriented Programming

Problem

Page 3: Introduction To Aspect Oriented Programming

DRY

Page 4: Introduction To Aspect Oriented Programming

Solutions

Some techniques include :

TemplateMetaprogramming

MetaObjectProtocol

Decorators

TemplateMethodPattern

RPC tools

Many of the Creational Patterns

MultipleInheritance and MixIns

ContextObject or ExplicitManagementOfImplicitContext

Page 5: Introduction To Aspect Oriented Programming

Solutions

Programming paradigm solution deal with this problem is :

Aspect Oriented Programming

Page 6: Introduction To 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

Page 7: Introduction To Aspect Oriented Programming

Intro

Software development technique that :

Increase modularity

Managing cross cutting concerns

Infrastructure composition

Page 8: Introduction To Aspect Oriented Programming

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

Page 9: Introduction To Aspect Oriented Programming

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

Page 10: Introduction To Aspect Oriented Programming

Features

Page 11: Introduction To Aspect Oriented Programming

Features

Page 12: Introduction To Aspect Oriented Programming

Benefits

Clean Code

Reduce Repetition

Encapsulation

Page 13: Introduction To Aspect Oriented Programming

Aspects

Encapsulating

Wrapper

SRP

Decorator Pattern

OCP

Page 14: Introduction To Aspect Oriented Programming

Aspects Lifetime

OnStart

OnSuccess

OnExit

OnError

Page 15: Introduction To Aspect Oriented Programming

Types

Interceptors

IL Code Weaving

Page 16: Introduction To Aspect Oriented Programming

Interceptors

Calls to class methods or properties

IoC Container

No post compilation

Dynamic Proxy

Page 17: Introduction To Aspect Oriented Programming

Interceptors

Common use of IoC Conainer

Calling Code IoC Container

IMyInterface

MyClass :IMyInterface

Page 18: Introduction To Aspect Oriented Programming

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

Page 19: Introduction To Aspect Oriented Programming

IL Code Weaving

Run after compilation

Post process

Page 20: Introduction To Aspect Oriented Programming

IL Code Weaving

Common Tool to use :

Page 21: Introduction To Aspect Oriented Programming

Example

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

SayHelloToAOP

Page 22: Introduction To Aspect Oriented Programming

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