Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Common use for AOP concept "introduction"

 
Greenhorn
Posts: 16
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the real world or common scenario where we need or want to use AOP introduction or adding new method/functionality to an object. In Spring case, on a bean.
 
Bartender
Posts: 1042
19
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Alder Potenz wrote:What are the real world or common scenario where we need or want to use AOP introduction.



Logging and [method] security are two scenarios.  This wiki link describes some more Cross Cutting Concerns

However the main idea is to try and address two issues that are common among badly designed systems, namely; Code Scattering and Code Tangling.

Code scattering is often referred to as "spaghetti code", where you see the same code repeated many times in order to achieve the same results.  For example when a class method has had many lines of code added to log the initial state and arguments, and then the final state.  This can be solved with AOP, which can be setup with SpringAOP which would implement the logging functionality behind the scenes.  

Code tangling refers to the scenario where we have a specific piece of code performs unrelated multiple objectives, often after a period of maintenance programming when a bug fix is implemented badly.  This is associated with the concept of code cohesion, where we want the code to only do one thing.    

There's a good answer in stack overflow that shows examples; StackOverflow - AOP

From a Java Spring perspective you can use Springs own implementation (SpringAOP) or use Spring to configure AspectJ.  AspectJ offers more features and could be used without Spring.    

AOP has its own terms [which I think are a bit confusing], and how this is actually done requires a bit a in depth knowledge of spring internals and since you asked for an introduction I'll leave you to research this.   SpringAOP Docs      

   
 
Alder Potenz
Greenhorn
Posts: 16
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply. Sure, I will research deeper with the AOP concepts.

Another question with one of Spring AOP feature, "introduction" on when we can introduced s new method. When we will usually need to do this?

I have attached an image representation.
Capture.PNG
[Thumbnail for Capture.PNG]
Why Introduced a new method?
 
Peter Rooke
Bartender
Posts: 1042
19
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before, after, and during a method.  AspectJ may offer different options (advise), but cannot comment as I don't know it that well.

Types of [SpringAOP] advice:

Before advice: Advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).

After returning advice: Advice to be executed after a join point completes normally: for example, if a method returns without throwing an exception.
After throwing advice: Advice to be executed if a method exits by throwing an exception.
After (finally) advice: Advice to be executed regardless of the means by which a join point exits (normal or exceptional return).
Around advice: Advice that surrounds a join point such as a method invocation. This is the most powerful kind of advice. Around advice can perform custom behavior before and after the method invocation. It is also responsible for choosing whether to proceed to the join point or to shortcut the advised method execution by returning its own return value or throwing an exception.



Taken from the spring docs Spring Docs
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!