Weaving

We, as developers, write business logic and the aspect code in two separate modules. Then, these two have to be combined as a proxied target class. The process of plugging the aspect in the business logic code is known as weaving. Weaving can happen at compile-time, load-time, or runtime. Spring AOP does weaving at runtime.

Let's take a very simple example to understand the discussed terminologies. My son loves watching dramas. So, we go to watch one. As we are all aware, we cannot enter unless and until we have an entry pass or a ticket. Obviously, we need to collect them first. Once we get the tickets, my son drags me to the seat and shows me the seat in excitement. The show starts. It is a funny drama for kids. All kids laugh at the jokes, clap for the dialogue, and get excited during the dramatic scenes. At interval, most of the audience goes to buy popcorn, snacks, and cold drinks. Everyone enjoys the drama, and leaves happily through the exit. Now, you must be thinking that we all know this. Why are we discussing this, and what is its relation to the aspect? Are we not going away from the discussion? No, we are on the right track. Just wait for a while, and you all will also agree. Here, watching the drama was our main task; now, let's say it's our business logic or core concern. Purchasing the tickets, paying the money, entering the theater, and leaving it once the drama is over are the functionalities that are the part of the core concern. However, we cannot just sit quietly; we react on what is going on. We clap, laugh, and sometimes even cry. However, are these the main concerns? No! But without them, we cannot imagine the audience watching the drama. These will be the supportive functionalities that each audience does spontaneously. Correct! These are the cross-cutting concerns. The audience won't get instructions for cross-cutting concerns individually. These reactions are the part of aspects having advices. Some will clap before the drama, a few after the drama, and the most excited whenever they feel. These are nothing but before, after, or around advices of the aspect. If the audience doesn't enjoy the drama, they may leave in between, which is similar to the after throwing exception. On a very unfortunate day, the show may get cancelled or even stopped in between, which needs to be introduced by the organizers as an emergency. I hope you now know the concepts as well as their practical approach. We will cover this and many more in the demo shortly.

Before moving on with the demonstration, let's first discuss some of the AOP frameworks on the market, which are as follows:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.67.251