class filterChain{ private List<Filter> filters; public void addFilter(Filter filter){ filters.add(filter); } public void do(HttpRequest request){ for(Filter filter:filters){ filter.do(request); } } } public class ConcreateFilter1:Filter{ public void do(HttpRequest request){ // } } public class ConcreateFilter2:Filter{ public void do(HttpRequest request){ // } } public class Client{ public void main(String[] args){ HttpRequest request = ..... FilterChain filterChain = new FilterChain(); filterChain.addFilter(new ConcreateFilter1()); filterChain.addFilter(new ConcreateFilter2()); filterChain.addFilter(new ConcreateFilter2()); filterChain.do(request); } }
原文:http://www.cnblogs.com/hfultrastrong/p/7758182.html