What is chain.doFilter doing in Filter.doFilter method?

后端 未结 6 1918
予麋鹿
予麋鹿 2020-12-08 06:51

In a Filter.doFilter method I made this call chain.doFilter.

What is doFilter doing inside a doFilter? Isn\'t it a recursive call?

6条回答
  •  遥遥无期
    2020-12-08 07:17

    Not having any code that you are talking about, I can only assume that you something like:

    class Filter implements FilterAPI {
      private FilterAPI chain;
      FilterAPI(FilterAPI chain) { this.chain = chain; }
      @override void doFilter (Set setToFilter) {
        // do some filtering on setToFilter
        chain.doFilter(setToFilter);
      }
    }
    

    If that is the case, then you are not calling anything recursively, you are calling doFilter() on a different object. As mentioned on an another answer, this is the well known Chain of Responsibility design pattern.

提交回复
热议问题