Archive for April, 2009

A good resource for Spring AOP

Monday, April 27th, 2009

A good resource for spring and AOP, “Spring 2.5 Aspect Oriented Programming“; has been published by Packt Publishing. I strongly suggest reading if you are a little bit familiar with Spring and interested in AOP.

Before you start reading my review about it, you can find more information about the book and how to get it, at this page.

Although Spring Framework has been seen as just an IoC container by some of the programmers, most of the programmers nowadays start to realize that this kind of view would be an over simplification of its capabilities. It has many features and one of them is using it for AOP. In book Spring 2.5 Aspect Oriented Programming written by Massilimiano Dessi and published by Packt Publishing, the use of Spring for AOP is well explained.

First of all, the need for AOP is explained in an analytical way, allowing readers to make comparison between a scenario with and without help of AOP. After this persuasive attitude, the introduction of AOP specific concepts (such as “pointcut”, “joinpoint”, “advice”) and introduction to some more Spring-AOP specific concepts (such as advisor) are provided. A language that is going to be used throughout the book is built in the beginning; and this enables readers to gain a better insight about the AOP paradigm while reading the book.

As well as describing how to realize AOP using Spring, chapters 2-4 also explain what is happening behind the scene. In this sense, this part of the book might be used as a “Cookbook”. Despite existence of diverse options while using Spring; some advice has been given about when to use which, depending on the context. While illustrating the use of AOP by giving some simple examples; the book also explains what kind of dilemmas might a programmer get into and make suggestions about which way would be more convenient.

After giving those details, the book comes back to a more conceptual point about AOP. From the beginning, a concept such as “croscutting concerns” has been mentioned as the most fundamental reason why AOP has been evolved. As object oriented programmers, we have experience about a lot of scenarios and we even have design patterns that help us a lot. However, when we decide to use AOP in our applications; the need to have some kind of decision mechanism that regards when to use it confronts us; since it is a new paradigm compared to OOP. At first glance, this may seem like an easy task; but not at all! While programmers are still arguing about the patterns and anti-patterns about AOP, there are some scenarios that is perfectly legal to use AOP. Some of them are concurrency, caching, security / role assignment. Use of AOP in those scenarios is illustrated in the book in a dialectic manner. First, implementation without using AOP and then with the use of AOP is provided; which enables readers to make comparison between them. This chapter illustrates very typical scenarios in which the use of AOP is approved and perfectly legal.

Domain Driven Design is very popular nowadays and the book connects AOP with it in chapters 6 and 7. First of all; without causing reader to get drown details, the relevant concepts are identified. Before applying AOP, a good Object-Oriented design has been given. Domain layer is separated from application and infastructure layers. Some of the croscutting concerns are identified and the reader is informed about how they are going to be handled. Moreover, the domain objects are designed in such a way that they would be able to take advantage of inversion of control (IoC). Simply, “Model” is created on this chapter, which is going to be associated with a “View” and a “Controller” in the subsequent chapter. Spring MVC has been used in chapter 7 in order to associate Model in chapter 6 with an appopriate view and controller. For readers who are not familiar with Spring MVC; a little information is provided, but there are lots of documentation in World Wide Web for Spring MVC; one of those should be read before starting this chapter. In chapter 7, AOP has been used for caching, concurrency, security in a sensible manner.

To conclude, the book Spring 2.5: Aspect Oriented Programming is an excellent source for programmers who are familiar with OOP, Spring Framework and interested in applying AOP on a real project.