Comparison
InterceptorvsProxy pattern
Interceptor
logging appeared around every method in the service and there is no line of your code that calls it.
A hook that a framework runs around a call, letting cross-cutting behaviour be attached without editing the target — the mechanism behind aspect-oriented programming, servlet filters, gRPC interceptors and most annotation-driven transactions. It is a decorator that you did not write and cannot see at the call site, which is both the appeal and the cost. Debugging is where the bill arrives: the stack trace names classes nobody wrote.
Full entry →Proxy pattern
the object looks and behaves exactly like the real one, and its whole job is deciding whether the call gets through.
A wrapper with the same interface as its subject whose purpose is to control access to it — checking permission, deferring creation, or standing in for something remote. It shares its shape with the decorator and differs in intent: a decorator adds behaviour the caller wants, a proxy manages access the caller should not have to think about. Proxies typically control the subject's lifetime as well, where decorators are handed one already made.
Full entry →