zoukankan      html  css  js  c++  java
  • 组合模式

    组合模式(Composite Pattern),又叫部分整体模式,是用于把一组相似的对象当作一个单一的对象。组合模式依据树形结构来组合对象,用来表示部分以及整体层次。这种类型的设计模式属于结构型模式,它创建了对象组的树形结构。

    这种模式创建了一个包含自己对象组的类。该类提供了修改相同对象组的方式。

    import java.util.ArrayList;
    import java.util.List;
    
    public class CompositeDemo {
        public static void main(String[] args)
        {
            Container Container=new Container();
            Container.add(new Button()).add(new CheckBox());
        }
    }
    
    abstract class Component
    {
        abstract Component add(Component component);
    }
    
    class Container extends Component
    {
        private List<Component> components=new ArrayList() ;
        public Component add(Component component){
            components.add(component);
            return this;
        }
    }
    
    class Button extends Component
    {
        @Override
        Component add(Component component) {
            // TODO Auto-generated method stub
            return null;
        }
        
    }
    
    class CheckBox extends Component
    {
        @Override
        Component add(Component component) {
            // TODO Auto-generated method stub
            return null;
        }    
    }
    View Code
  • 相关阅读:
    Ubuntu的网络共享
    一次网络请求是如何实现的
    一次web请求发生的神奇故事
    Header解析
    Shiro入门指引
    Shiro入门资源整理
    Shiro在SpringBoot中的使用
    Shiro源码解析-Session篇
    Shiro源码解析-登录篇
    9.nginx使用redis用缓存
  • 原文地址:https://www.cnblogs.com/liandy0906/p/7248124.html
Copyright © 2011-2022 走看看