Interceptor Pattern

by moodyharsh 2016-04-27
interceptor

It looks like this,

class Invocation {
    public String method;
    public Array<Object> args;
}

Event = Invocation

class Interceptor {
    public Interceptor next;
    public intercept(Invocation v);
    private dispatch(Invocation v);
    private delegate(Invocation v);
    intercept = trigger = execute
}

Interceptor = System = Command

When dealing with legacy code it becomes,

  • Wrapper
  • Facade
  • Adapter
  • Proxy
  • Mediator
  • Command

By composing multiple interceptors with the help of next,

  • Decorator
  • Delegation
  • Chain of Command
  • Pipes and Filters
  • Front Controller

You can easily use ServiceLocater at various points in the code to simulate AOP and implement Stategy pattern, easily.