I'm designing a class that takes:

1 - An initial set of items (a simple collection/list)

2 - 1 or more Filter objects, that take the initial set of items and return a new set. Each Filter object may return a different set of items, so the main class performs and intersection of the result of these sets. Some of these Filter objects, however, perform a subset operation based on the resulting set of the intersection of the sets from the other Filters instead of the initial set.

What should I call this class if its main function is to return a new set by performing intersection and subset operations based on a given set and one or more Filter objects?

The -partial- interface for the Filter class looks like this:

constructor(ItemsSet set, options) : ItemsSet
getFilteredSet() : ItemsSet

And for the class that I'm designing:

constructor(ItemsSet mainSet, filters) : ItemsSet
getSet(): ItemsSet

I was thinking:





I'm leaning towards SubsetOfItems but this class will not always have a filter that performs a subset of the resulting set from the intersection of the other sets. Hopefully that makes sense.

In other words, the operation can be intersection-only, subset-only, intersection AND subset.

  • 2
    The obvious name here is Filter. You even used it in the question. What am I missing?
    – John Wu
    Oct 28, 2021 at 0:00

2 Answers 2


You appear to be describing the Composite pattern. Your class which performs the intersection of all different sets is simply a composite object. Without knowing the full details of your use case, I would however recommend accepting the set from the filter method rather than at through the constructor.

For example, in Java, it would look like something like this:

public interface Filter<T> {
  Set<T> filter(Set<T> xs);

public interface FirstFilter<T> implements Filter<T> {
  // ...

public interface SecondFilter<T> implements Filter<T> {
  // ...

public interface FilteringOnSubset<T> implements Filter<T> {
  // ...

public interface IntersectionCompositeFilter<T> implements Filter<T> {
  public IntersectionCompositeFilter(Filter<T>... filters) {
    // ...
  // ...

public static void main(String args[]) {
  Filter<String> filter = new FilteringOnSubset<>(new IntersectionCompositeFilter<>(new FirstFilter<>(), new SecondFilter<>()));
  Set<String> xs = ...
  Set<String> filteredXs = filter.filter(xs)
  • Thank you SO much for taking the time to post this. I had read about the composite pattern before but never really implemented it... until now. Wow, it produces such a beautiful code. I love this so much I ended up implementing the pattern somewhere else in my codebase. I got to say I'm impressed.
    – rafark
    Nov 10, 2021 at 21:05
  • PS. I ended up naming the main class CompositeFilter.
    – rafark
    Nov 10, 2021 at 21:07

The problem from a natural English point of view is that an object which performs filtering, is called a "filter". However you've already employed this word to refer to the objects that perform each individual stage of filtering.

The obvious name for an object that applies a series of filters, would be something like "FilterBatch" or "FilterPipeline" or something in that vein.

However, if I understand correctly that this filter batch object actually has complicated internal logic for applying each stage and for determining how the inputs and outputs of each stage connect, then it may be more appropriate to talk in terms of a "FilterEngine" or "FilterMultiplex".

  • Thanks for your comment. I ended up going with the "composite" suffix based on the answer above.
    – rafark
    Nov 10, 2021 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.