• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

What's the difference between events and AOP?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know they are both different in implementation, but I am asking in terms of concept. I understand AOP to mean defining advice that react at join points. Event listeners react whenever the event they are attached to is triggered. Please let me know if this is incorrect.

If it isn't, it means they are interchangeable. So, why does Spring framework have both? I imagine AOP is a cleaner version of event listeners, whereby the event is being triggered as join points and listened to by target advice
 
Saloon Keeper
Posts: 22989
156
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Nmeri!

An event is an indication of change of state, often accompanied by information relating to that change of state. For example, the mouse button is pressed. Its new state is "down".

Aspect-Oriented programming is a sideways sort of design in a world where we traditionally code up-and-down. AOP allows us to customize classes and methods by injecting extra code to various points in the logic. For example, I could AOP-augment graphical drawing routines to log entry into and return from those routines. Entry and return are not considered to be "events", just logic flow. But AOP can add the extra logging statements to the code without requiring the application programmer to touch the original code. And likewise to remove those statements.
 
Nmeri Alphonsus
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:Welcome to the Ranch, Nmeri!

An event is an indication of change of state, often accompanied by information relating to that change of state. For example, the mouse button is pressed. Its new state is "down".

Aspect-Oriented programming is a sideways sort of design in a world where we traditionally code up-and-down. AOP allows us to customize classes and methods by injecting extra code to various points in the logic. For example, I could AOP-augment graphical drawing routines to log entry into and return from those routines. Entry and return are not considered to be "events", just logic flow. But AOP can add the extra logging statements to the code without requiring the application programmer to touch the original code. And likewise to remove those statements.



Many thanks for welcoming me . I've always heard aspects consist of CROSS-CUTTING topics not directly pertaining to the business logic i.e. transactions, logging etc. Hearing your perspective is a new one. You make it sound like I should think of aspects more in terms of decorators. Which isn't entirely out of place, considering how the weaving process makes use of proxies to instrument its advices.

I think that concept differentiates AOP and events; one involves auxiliary business logic that kind of belongs to another scope outside the one that triggered it (thinking in terms of back end events such as sending invoices after purchase on an e-commerce site). "Scope" here can be defined as another business (service?) than the current one.
On the other hand, AOP, while equally catering to auxiliary concerns, these concerns serve more of an upgrading/decorating purpose. They're not critical to the business. They are usually meta.

These are just my thoughts, based on my understanding of your answer. Even though it's outside the scope of the current question, I wonder what you make of my earlier postulation of marrying both concepts i.e. instrumenting event listeners. Looking at them outside the context described above, what adversity could come from defining/weaving/pairing events and their listeners outside the target objects they affect?

The only one I can think of is readability i.e. it might prove challenging following/understanding side effects or full reach if certain actions are defined outside the program's flow
 
Bartender
Posts: 1078
19
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically AOP addresses two concerns, namely that of Code Tangling and Code Scattering.    

They're not critical to the business

Don't be too sure. For example, its often a requirement is to log activities for security and/or audit purposes.  
 
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic