zoukankan      html  css  js  c++  java
  • design_model(8)composite

    1.组合模式

    将一组相似的对象根据一个树状结构来组合,然后提供一个统一的方法去访问相应的对象,以此忽略掉对象与对象集合之间的差别。

    2.实例

    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();
    	}
    }
    
  • 相关阅读:
    Cmder配置
    uboot移植
    嵌入式产品开发技术问题
    flexbox布局
    使用PS过程
    STM32 使用 FreeRTOS过程记录
    TTL、RS232、RS485、串口
    用纯css改变下拉列表select框的默认样式
    task9暂存
    Hello World
  • 原文地址:https://www.cnblogs.com/gg128/p/9570172.html
Copyright © 2011-2022 走看看