Interceptor Pattern

Posted by moodyharsh on 2016-04-27

It looks like this,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 we get,

  • Decorator
  • Delegation
  • Chain of Command
  • Filters

When combined with metadata meta-object-programming,

  • Strategy
  • ServiceLocator
  • Front Controller

It can be combined with a Message Bus easily as well.
It can used as the System in Entity-Component-System pattern.