1.Combinatorial pattern
A group of similar objects is combined according to a tree structure, and then a unified method is provided to access the corresponding objects, thus ignoring the differences between objects and object sets.
2.Example
public interface Workfile { public abstract void KillVirus(); } public class Floder implements Workfile { @Override public void KillVirus() { } } class ImageFloder implements Workfile { @Override public void KillVirus() { } } public class CompositeHandler { private ArrayList<Workfile> f1 = new ArrayList<>(); public void add(Workfile f) { f1.add(f); } public ArrayList<Workfile> getF1() { return f1; } public void killVirus() { for (Workfile workfile : f1) { workfile.KillVirus(); } } } public class Client { public static void main(String[] args) { Floder f2 = new Floder(); ImageFloder f3 = new ImageFloder(); CompositeHandler ch = new CompositeHandler(); ArrayList<Workfile> f1 = ch.getF1(); f1.add(f2); f1.add(f3); ch.killVirus(); } }