Open In App

Spring Boot – Difference Between AOP and OOP

AOP(Aspect-Oriented Programming) complements OOP by enabling modularity of cross-cutting concerns. The Key unit of Modularity(breaking of code into different modules) in Aspect-Oriented Programming is Aspect. one of the major advantages of AOP is that it allows developers to concentrate on business logic. It is more convenient to use because changes need to be done in only one place. AOP is used along with spring Ioc to provide a very capable middleware solution.

Note: Cross cutting concerns are one of the concerns in any application such as logging, security, caching, etc. They are present in one part of the program but they may affect other parts of the program too.



AOP is used along with Oop as it also works around classes and objects, etc. We can also say that Oop is a basic term for AOP. Different Frameworks used in Aop are AspectJ, JBoss, and Spring. AOP makes the program loosely coupled. AOP separates business logic from cross-cutting concerns. The aspect class which contains cross-cutting concerns is annotated by @Aspect and @EnableAspectJAutoProxy annotations

AOP has different terms like Aspect, Weaving, different types of advices, JoinPoints and Pointcut expressions, etc. These terms are explained below:



Illustration: A pointcut expression with before advice:

// Annotation
@Before("execution(* abc.efg.gettingstarted.dao.*.add(..))")

public void allMethods(Point Point) 
{  // Aspect body }

Object-Oriented Programming

The object-oriented programming model works around classes and objects. The main building blocks of Oop are classes, objects, methods, attributes, etc. Oop has various advantages such as code reusability, flexibility, etc. It also maintains modularity using classes.

Note: Object is an instance of class and class is a blueprint of an object created.

The Key unit of Modularity(breaking of code into different modules) in Object-Oriented Programming is class. Oop contains objects, classes, interfaces, etc. Oop lacks the feature of using cross-cutting concerns. It consists of various concepts such as Data abstraction, Encapsulation, Polymorphism, and Inheritance.

Illustration: If there is a fruit class then apple, orange, banana are various objects of the fruit class.

Article Tags :