-1

What do you think about putting business logic into a Spring interceptor/Advice? Is it a bad practice?

Which kind of business logic would you put in an interceptor? just validations?

What I see is that business logic in an interceptor is harder to see because there is not a clear chain of method calls to follow. And also business logic should is supposed to be at Domain Objects if you use domain driven design.

Thanks in advance.

alderaan
  • 23
  • 1
  • 5

2 Answers2

0

As a general rule, AOP interceptors should be used for cross-cutting concerns, not for base business logic. I've seen applications that use AOP, and some developers swear by them. If find them a nightmare to debug and test.

It quickly becomes a combinatorial problem, finding the different aspects that intersect to combine to create the desired user behavior. It is much easier to determine business logic in systems that are linear and explicit in their business logic invocation.

Rob Conklin
  • 8,806
  • 1
  • 19
  • 23
0

An interceptor is a method that you can interpose in the invocation flow. This generally executes before and after a method (or a web request).

The great benefit of interceptors is that they give you a way to add functionality to your business methods without modifying the methods' code.

I think purpose of interceptors is not to have business logic, but to do pre and post checks so that your business logic is performed in a proper way. Some of them are validating user's input, putting security check etc.

Guanxi
  • 3,103
  • 21
  • 38