Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Aspect Oriented Programming? [duplicate]

Tags:

aop

Duplicate:

What is aspect-oriented programming?

Every time I here a podcast or read a blog entry about it, even here, they make it sound like string theory or something. Is the best way to describe it OOP with Dependency Injection on steroids?

Every time someone tries to explain it, it’s like, Aspects, [Adults from Peanuts Cartoon sound], Orthogonal, [more noise], cross cutting concerns, etc. Seriously, can anyone describe it in layman’s terms.

like image 368
Charles Graham Avatar asked Nov 26 '08 03:11

Charles Graham


People also ask

What is meant by Aspect-Oriented Programming?

In computing, aspect-oriented programming (AOP) is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns.

What is Aspect-Oriented Programming example?

There are various common good examples of aspects like logging, auditing, declarative transactions, security, caching, etc. The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect.

What does Aspect-Oriented Programming address?

Aspect oriented programming(AOP) as the name suggests uses aspects in programming. It can be defined as the breaking of code into different modules, also known as modularisation, where the aspect is the key unit of modularity.

Is Aspect-Oriented Programming still used?

Nowadays I see some AOP still around, but it seems to have faded into the background. Even Gregor Kiczales (inventor of AOP) called it a 15% solution. So I guess AOP has its reason for existence, but it depends on the individual developer to use it the right way.


1 Answers

Laymans terms so let me give you an example. Let's say you have a web application, and you need to add error logging / auditing. One implementation would be to go into every public method and add your try catch blocks etc...

Well Aspect oriented says hogwash with that, let me inject my method around your method so for example instead of calling YourClass.UpdateModel(), the system might call,

LoggingHandler.CallMethod() this method might then redirect the call to UpdateModel but wraps it in a try catch block to handle logging errors.

Now the trick is that this redirection happens automagically, through configuration or by applying attributes to methods.

This works for as you said cross cutting things which are very common programing elements that exist in every domain, such as: Logging, Auditing, Transaction Mgmt, Authorization.

The idea behind it is to remove all this common plumbing code out of your business / app tier so you can focus on solving the problem not worrying about logging this method call or that method call.

like image 135
JoshBerke Avatar answered Oct 12 '22 06:10

JoshBerke