Aspect-Oriented Programming Introduction

Updated: May 19


AOP Main Image
Aspect-Oriented Programming

In this blog, we will learn about Aspect-Oriented Programming (AOP),

  • How does it provide separation of cross-cutting concerns?

  • How does it make code cleaner?

  • How does it improve code reusability?


This blog is the first part of the three-part blog series. Here we will get ourselves familiarise with Aspect-Oriented Programming using a real-life example.


Aspect-Oriented Programming(AOP) is a programming paradigm.

There are a few terms that we will hear a lot, whenever we talk about Aspect-Oriented Programming:

  • Cross-Cutting Concerns: All functionalities that are not business logic, categorised as cross-cutting concerns, such as logging, security, exception handling.

  • Advice: Advices are the instruction given to the program to perform the same thing whenever the defined conditions met.

It is very similar to the advice that we receive from our parents or someone else, and we do it whenever the situation arises. Like our parents told us, do not take anything from a stranger.

Here, Advice is not to take anything from a stranger.

  • Pointcut: It is a condition that we specify so that it executes the advice.

In our previous example of advice, the Stranger giving something to us is the pointcut.

  • Aspect: Aspect is the combination or modularisation of advice given for different cross-cutting concerns.

  • Joinpoint: It is a point during the execution of the program or function.


Real-Life Example


Explaining AOP with real life example
Understand AOP with real life example


In our complete life, we follow a few instructions whenever the situation arises, irrespective of other stuff.


Elders instructed us to brush our teeth daily.


Here,

  • Cross-cutting concern: Cleaning of teeth.

  • Advice: Brush your teeth.

  • Pointcut: In morning and Night.

We skip brushing our teeth sometimes if we are sick. Similarly, if a program is not in the proper state, it can sometimes ignore the advice.


I think, by now we have understood the idea of Aspect-Oriented Programming.


Let’s answer our question.


Answering how does AOP, helps in separation of cross-cutting concern, code reusability, and cleaner code
How is AOP helpful?


How does it provide separation of cross-cutting concerns?

It centralises all advice under different aspects, like creating one aspect for logging, security, etc. Therefore, it separates cross-cutting concerns from business logic.


How does it make code cleaner?

Since AOP separate cross-cutting concern from business logic, it will increase the modularity and result in cleaner code.


How does it improve code reusability?

Since all cross-cutting concerns are centralised, we can directly use it only without rewriting the same set of instruction again and again.


Personal View


Personal View About AOP
Personal View

Although Aspect-Oriented Programming states that we can separate cross-cutting concerns from Business logic, we can also use it for some business logic if it is reused in different services. Therefore, cross-cutting concerns are not limited to logging, security, and exception handling; it can also include all such functions re reused in software.



I hope this blog helps you to develop an understanding of Aspect-Oriented Programming.


Comments and feedback are most welcomed.


Follow me on Linkedin, Github.


Thanks for reading. Happy Learning 😊

413 views

Recent Posts

See All