Spring Boot - Difference Between AOP and OOP
Last Updated : 28 Feb, 2022
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:
- Aspect: The cross-cutting concerns are modularized as Aspect. The classes which contain such cross-cutting concerns are annotated with @Aspect annotation.
- Join point: Method execution is represented by using Joinpoint.
- Advice: Aspect takes action on a particular Joinpoint. This action depends on various advice which is explained below:
- Before advice: It runs before the method execution.
- After returning advice: It runs after the result is returned by the method.
- After throwing advice: It runs after an exception is thrown by the method.
- After (finally) advice: It is executed after method execution or after an exception is thrown or the result is returned by the method.
- Around advice: It can perform the behavior before and after the method invocation.
- Pointcut: Pointcut is a signature that matches the join points.
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.
Similar Reads
Spring Boot - Service Class Example for Displaying Response Codes and Custom Error Codes Sometimes the error or status messages in webpages would be different from the default error message thrown by Tomcat (or any other server). An important reason for this is websites want to look unique in their approach to their users. So, a customized page for displaying status codes is always bett
6 min read
Spring Boot - Create a Custom Auto-Configuration Usually, we might be taking a maven project or grade project for Spring Boot related projects. We will be adding the dependencies in pom.xml (in case of a maven project). In a spring application, Spring Boot auto-configuration helps to automatically configure by checking with the jar dependencies th
4 min read
Spring Boot - Consume Message Through Kafka, Save into ElasticSearch, and Plot into Grafana In this article, we are going to make a program to produce some data using Kafka Producer which will consume by the Kafka Consumer and save into the elastic search DB, and later on, plot that JSON data into the Grafana dashboard. Start with configuring all the required software and tool. Requirement
7 min read
How to Implement AOP in Spring Boot Application? AOP(Aspect Oriented Programming) breaks the full program into different smaller units. In numerous situations, we need to log, and audit the details as well as need to pay importance to declarative transactions, security, caching, etc., Let us see the key terminologies of AOP Aspect: It has a set of
10 min read
Spring Boot - AOP(Aspect Oriented Programming) The Java applications are developed in multiple layers, to increase security, separate business logic, persistence logic, etc. A typical Java application has three layers namely they are Web layer, the Business layer, and the Data layer. Web layer: This layer is used to provide the services to the e
4 min read
Spring Boot - Cache Provider The Spring Framework provides support for transparently adding caching to an application. The Cache provider gives authorization to programmers to configure cache explicitly in an application. It incorporates various cache providers such as EhCache, Redis, Guava, Caffeine, etc. It keeps frequently a
6 min read
Spring Boot - AOP Around Advice Aspect-oriented programming(AOP) as the name suggests uses aspects in programming. It can be defined as the breaking of code into different modules, also known as modularisation, where the aspect is the key unit of modularity. Aspects enable the implementation of crosscutting concerns such as transa
6 min read
Spring Boot - Auto-configuration Spring Boot is heavily attracting developers toward it because of three main features as follows: Auto-configuration - such as checking for the dependencies, the presence of certain classes in the classpath, the existence of a bean, or the activation of some property.An opinionated approach to confi
5 min read
Spring Boot - EhCaching EhCache is an open-source and Java-based cache. It is used to boost performance. Its current version is 3. EhCache provides the implementation of the JSR-107 cache manager. Features of EhCache are given below: It is fast, lightweight, Flexible, and Scalable.It allows us to perform Serializable and O
5 min read
Difference Between Spring Boot Starter Web and Spring Boot Starter Tomcat Spring Boot is built on the top of the spring and contains all the features of spring. And is becoming a favorite of developers these days because of its rapid production-ready environment which enables the developers to directly focus on the logic instead of struggling with the configuration and se
3 min read