Aspect Oriented Programming – Part 1

Today, I’m going to start new series of tutorials on a new topic. i.e. Aspect-Oriented Programming, in which you will learn about the new programming paradigm (though it’s too old), its basics, the core concept, comparison with current programming paradigms like Object Oriented Programming (OOA) and finally implementation for any real-world problem or scenario.
I will post 3, 4 articles for this topic, dividing this into the following possible sections
- Object-oriented programming approach and some flaws
- The core theme of Aspect-Oriented Programming
- Solutions provided by AOP against OOP flaws
- Important terms used in AOP talk
- A programming example with OOP and AOP
- Introduction of AspectJ, a java implementation of the aspect-oriented approach.
Object-Oriented Programming Approach
Computer software or programs are automation of real-world scenarios, a transformation of manual work into computer-operated systems. Many approaches are in practice to design and develop more usable, user-friendly, easily evolvable and maintainable computer systems. Different approaches handle the under-considerate domain with their own style. The object-oriented approach focuses on data, takes anything in the real world as data having some attributes (data fields) and some operations (methods). This approach evolves in the sixth decade of the last century when the computer system becomes much more complex and the current programming paradigms were not much capable to cope with required features to facilitate both developers and end-users. At that moment researchers made on some new style of programming and then introduced a “data-focused” approach. i.e. object-oriented programming where everything in real life was considered an object, in other words, every noun is an object. We design systems based on these nouns in real-world like Pay, Account, Employee, Product, PurchaseOrder, Invoice etc
The object-oriented approach was at its peak in the mid-’80s and late ’90s, even still a great number of computer systems are being developed using the object-oriented approach, but from its birth, it is faced many critics. Though the implementer of this approach is introducing many new features day by day in their respective languages compilers but only adding feature after feature into something don’t make it better. Polymorphism, encapsulation, abstraction no doubt are building blocks of any mature programming language and should be available implicitly, yet still, there are few areas where developers need more ease and re-usability of their efforts and code. Those areas were perceived and made research and then a new approach was presented to design and develop software modules with more ease in re-usability of existing code, more ease in extendability and maintainability. This approach was AOP.
Did you ever feel that while developing in an object-oriented world, you have you rewrite the same chunk of code in different classes/methods to achieve the same goal? like (as a very simple example) in the data access layer, you have to open a database connection, maintain its session, write a query, call to the database to fetch data and at the end, close the database connections and sessions. Like following
method Fetch_Employee_DATA{
open database session;
create a query to fetch data;
call to the database to fetch data;
close database session;
return results;
}
here the bold text is those lines of code you have to write in each method you call to fetch data from the database, other lines are method-specific and depends upon the business logic.
Like the other example, if you have to log each and every database call. i.e. the query to the database, its parameter, the returned results etc, then you have to write the same line of codes every time in each method that is going to interact with the database. The above method will look like
method Fetch_Employee_DATA{
log the start of method;
open database session;
create a query to fetch data;
log query and its parameters;
call to the database to fetch data;
close database session;
log returned data from the database;
log end of method;
return results;
}
Again the bold lines are those lines of code you are replicating in each method to achieve the same goal. Don’t you think you’re spending a lot of time writing the same bits of code when it comes to implementing the individual methods? These things like logging, security checking, transaction management are such aspects of the systems that are orthogonal to the specific application. Every organization need them and every developer has to implement them in their respected module, classes and methods. In short, the method hasn’t concern with these replicated lines, or the core concern of the method is to fetch employees, not to log database transactions, session maintenance etc. Every class or method is doing something extra time and again that doesn’t concern their core requirement.
For small projects for small level organizations, it may work. But what if you are going to design and develop a banking system, an ERP for a large scale company, or a payroll system for a big industry … where the modules are interlinked cohesively, the domain is very large, covering all business scenarios of under-considerate organization. In such a system, you can’t afford such a framework and design that is difficult to extend, maintain and reuse. You can’t let your developers spend time and resources over rewriting the same bit of code in every class and method, instead of focusing core business logic of that class. In other words, you can’t let everyone focus on those things that are not concerned with their core task.
Consider the above example again. You are working on a project (let’s suppose inventory management). While developing different features or modules, you have to call the database to fetch and insert data as per business logic and domain requirement. We have seen that in every method you write, you are writing the code of opening the database session and closing it properly. In a medium and large scale project, the number of methods doing the same things could be hundreds. Anyhow, you complete your task and deploy the application at the client site. Next time you are asked to maintain logs for each database interaction (as we discussed above) you instantly recall the number of classes and methods where you have to write code related to logging …. you have more than 40, 50 classes (let’s suppose) and there are hundreds of methods interacting with database. You have to open each method’s body and has to write logging code there
“Sir it will take atleast 4,5 days to complete this task”
“4, 5 days, but way, its really a simple task”
“indeed its simple but i have review each and every package, class and method to embed logging code there. To make sure the sustainability of application, i have to test it thoroughly to check that our existing application are new changes are running fine”
“hmmm ok, add someone else with you and try to complete it within 2,3 day, there are lot of other things too to do”
“sure i will”
This is the expected dialog between a developer and his manager/team lead while incorporation a simple change in running application. See, the actual lines that has to write in every method are very simple, just 2, 3 lines. But when it span over entire application with hundreds of packages/classes/methods then it becomes worst, consuming your more resources in term of human effort, time and budge.
Think again … is the logging concerned to method which was written to fetch data from database? Should a developer concern with database issues like opening a session and closing it properly who want to focus his attention to design an optimal query to fetch data from database?
In next post i will introduce Aspect Oriented Programming (AOP) and will discuss how AOP provides solutions for problems we discussed earlier.
Ans, its really a good post. you keep your style simple and understandable. I’m waiting for next post … plz be quick
Its quite helpful and great work.
Thanks athar for reading the post and for your comments. i will try my best to make it more simple in understanding.
kindly find 2nd part of this series at
http://aasims.wordpress.com/2009/11/04/aspect-oriented-programming-part-2/
Appreciate this post. Will try it out.
I always was concerned in this subject and stock still am,
appreciate it for putting up.
Here is my homepage ykychastity252682.webgarden.com
This design is spectacular! You definitely know how to keep a reader amused.
Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Fantastic job.
I really loved what you had to say, and more than that,
how you presented it. Too cool!
Feel free to visit my blog; Allura Fresh Reviews
I’ve been exploring for a little bit for any high quality articles or blog posts on this kind of space .
Exploring in Yahoo I at last stumbled upon this website.
Reading this info So i am glad to express that I’ve a very just right uncanny feeling
I found out just what I needed. I such a lot
indisputably will make certain to do not forget this site and give it a look
regularly.
Feel free to visit my site :: alineconaway564.mywibes.com
Do you mind if I quote a few of your posts as long
as I provide credit and sources back to your website? My blog site is in the exact same area of interest
as yours and my visitors would definitely benefit from some of the information you
provide here. Please let me know if this okay with you. Thanks a
lot!
It’s a shame you don’t have a donate button! I’d definitely donate to this excellent blog!
I suppose for now i’ll settle for bookmarking and adding your RSS feed
to my Google account. I look forward to brand new updates and will talk
about this site with my Facebook group. Chat soon!
Greetings from Carolina! I’m bored to death at work
so I decided to browse your website on my iphone during lunch break.
I enjoy the information you provide here and can’t wait to take a look
when I get home. I’m surprised at how fast your blog loaded on my cell phone ..
I’m not even using WIFI, just 3G .. Anyhow, superb site!
I like what you guys tend to be up too. This kind of clever work and coverage!
Keep up the fantastic works guys I’ve included you guys to
my own blogroll.
stromectol generic name
stromectol for humans
I was able to find good advice from your articles.
Heya! I understand this is sort of off-topic
but I had to ask. Does running a well-established blog like yours take a massive amount work?
I am completely new to operating a blog however I do write in my diary daily.
I’d like to start a blog so I will be able to share my own experience and views online.
Please let me know if you have any suggestions or tips for brand new aspiring blog owners.
Thankyou!
Feel free to visit my web page – Leaf Max CBD Oil
I feel that is among the such a lot vital info for me.
And i’m satisfied reading your article. But want to
observation on few normal issues, The web site taste is perfect, the articles is truly excellent : D.
Excellent activity, cheers
Hi there every one, here every person is sharing these knowledge, thus it’s pleasant to read this
webpage, and I used to go to see this blog everyday.
Here is my website: Nitro Strive Reviews
Hello! This is my first visit to your blog! We are a group of volunteers and starting
a new project in a community in the same niche.
Your blog provided us beneficial information to
work on. You have done a wonderful job!
My website – Keto BHB Plus
Thank you for some other excellent article. The place else may anybody get that kind
of info in such an ideal manner of writing? I have a presentation subsequent
week, and I’m at the search for such info.
Feel free to surf to my webpage – forum.adm-tolka.ru
My wife and i ended up being very happy Chris could finish up his
analysis through the precious recommendations he received through
your web page. It’s not at all simplistic just to find yourself
offering information and facts which usually the others might
have been trying to sell. We understand we now have the writer to thank for this.
The type of illustrations you made, the simple web site navigation, the relationships you can give support to instill – it’s mostly
unbelievable, and it’s really letting our son in addition to the family reason why
the situation is entertaining, and that is wonderfully
serious. Thank you for the whole lot!
my web page – Kurtis
I conceive this site has very excellent pent articles posts.
My page … Xtreme Shred Keto
I have to thank you for the efforts you have put in writing this site.
I really hope to view the same high-grade blog posts by you later on as well.
In truth, your creative writing abilities has inspired me to get my own website now 😉
My site – http://www.diigo.com
You’ve made some good points there. I checked on the internet to
find out more about the issue and found most individuals will go along with your views on this website.
Everything is very open with a precise description of the challenges.
It was truly informative. Your website is very useful.
Thank you for sharing!
Hurrah, that’s what I was exploring for, what a material!
existing here at this weblog, thanks admin of this website.
This is very interesting, You’re a very skilled
blogger. I have joined your rss feed and look forward to seeking more of your fantastic post.
Also, I have shared your site in my social networks!
Definitely consider that that you stated. Your favourite reason appeared
to be at the web the simplest thing to take into accout of.
I say to you, I certainly get annoyed while folks consider issues that
they plainly don’t know about. You managed to hit the nail upon the top
and defined out the whole thing with no need side effect ,
other people could take a signal. Will probably be
again to get more. Thank you!
Visit my webpage; Vigor Max (Garnet)
Excellent post. I was checking continuously this blog and I’m impressed!
Extremely useful information particularly the last part
🙂 I care for such info much. I was looking for this certain info for a very long time.
Thank you and best of luck.
My homepage – Renown CBD Oil
Hey! I know this is somewhat off topic but I was wondering which blog
platform are you using for this website? I’m getting tired of WordPress because I’ve had issues with hackers and I’m looking at
alternatives for another platform. I would be fantastic if you could point me in the direction of a good platform.
Seria muito interessante se você pudesse oferecer seu
conteúdo em formato RSS para que os visitantes pudessem ter acesso rápido.
Olá . Você oferecem consultoria ? gostaria de evoluir mais sobre este tema mas
este ainda é um novo mundo para mim. como posso contactar você?
Legal essa maneira de como você ilustrou o assunto do artigo.
Confesso que ainda estou um pouco sem rumo por não dominar
em sua plenitude o assunto, mas tenho interesse de
ver tuas novas postagens para me informar bem.
Agradeço pela ótima postagem!
Your method of explaining everything in this post is actually
pleasant, every one can simply be aware of it, Thanks a lot.
Nice read, I just passed this onto a friend who was doing
some research on that. And he actually bought me lunch
because I found it for him smile Therefore let me rephrase that:
Thank you for lunch!
my blog post: http://www.goldenanapa.ru/modules.php?name=Your_Account&op=userinfo&username=ShellshearApril
You made some decent points there. I did a search on the subject and found
most guys will approve with your blog.
my blog post – http://www.meteoritegarden.com
Hello.This article was extremely motivating, especially since I was browsing for thoughts on this issue last Friday.
Here is my blog post Vinyasa Organics Cream
Heya i am for the first time here. I found this board and I in finding It
really useful & it helped me out much. I am hoping to give something again and aid others like you helped me.
My website; Keto Tru Lean PiLLS [http://www.meteoritegarden.com]
I pay a visit each day a few web pages and sites to read posts, but
this web site presents feature based posts.
Today, while I was at work, my sister stole my iPad
and tested to see if it can survive a twenty
five foot drop, just so she can be a youtube sensation. My iPad
is now broken and she has 83 views. I know this is completely off topic but I had to share it
with someone!
This paragraph offers clear idea in favor of the new viewers of
blogging, that actually how to do running a blog.
Hmm is anyone else having problems with the images on this blog loading?
I’m trying to determine if its a problem on my end or if it’s the
blog. Any feed-back would be greatly appreciated.
Here is my site: Leafy Living CBD Reviews
Awesome article.
You actually make it seem really easy with your presentation but I to find this matter to be actually something which I feel I might never understand.
It kind of feels too complex and extremely vast for me.
I’m taking a look ahead on your next put up, I’ll attempt to get the hold of it!
I have read so many content regarding the blogger lovers but this
post is in fact a nice post, keep it up.
Pretty nice post. I just stumbled upon your
blog and wanted to say that I’ve truly enjoyed surfing around your blog posts.
After all I’ll be subscribing to your feed and I hope you write again very soon!
My web site: Zenzi CBD
Hello! I’ve been following your weblog for some time now and finally got the bravery
to go ahead and give you a shout out from Porter Tx!
Just wanted to say keep up the great job!
Will you be a togel online player? Have a look at news on my site for beginners to get the hottest information. Many
of correct estimations and how to delight in.
You actually make these kinds of seem simple with
your exhibition but Not long ago i find this kind of matter internet marketing actually a thing that
I think I might in person never understand. It seems as well complex
and very broad to me. I am looking forward on your coming post, Sick try to get
the hang of it!
Currently it sounds like Drupal is the top blogging platform available right now.
(from what I’ve read) Is that what you’re using on your blog?
Aw, this was an extremely nice post. Taking a few minutes and actual effort to create a good article?
but what can I say? I procrastinate a whole lot
and don’t seem to get anything done.
Check out my web-site: http://duna-anapa.net.ru/modules.php?name=Your_Account&op=userinfo&username=GovanKatharina
For most recent information you have to visit world-wide-web and on the web I found this site as a most
excellent site for latest updates.
my web page: http://159.203.199.234