zoukankan      html  css  js  c++  java
  • 装饰器模式

    package shejimoshi.zhuangshiqi.car;
    //car接口
    public interface Car {
     public abstract void color();
     public abstract void size();
    }
    

      

    package shejimoshi.zhuangshiqi.car.juticar;
    
    import shejimoshi.zhuangshiqi.car.Car;
    //具体car(原版车)
    public class oldcar implements Car {
    
    	@Override
    	public void color() {
    		System.out.println(" ");
    
    	}
    
    	@Override
    	public void size() {
    	  System.out.println(" ");
    	}	
    
    }
    

      

    package shejimoshi.zhuangshiqi.car.zhuangshi;
    
    import shejimoshi.zhuangshiqi.car.Car;
    //装饰类
    public class zhuangshi implements Car {
    	protected Car car;
    
    	public zhuangshi(Car car) {
    		this.car = car;
    	}
    
    	public void color() {
    		car.color();
    
    	}
    	public void size() {
    		car.size();
    	}
    
    }
    

      

    package shejimoshi.zhuangshiqi.car.zhuangshi;
    
    import shejimoshi.zhuangshiqi.car.Car;
    //具体装饰车BMW(改造后)
    public class bmw extends zhuangshi {
    
    	public bmw(Car car) {
    		super(car);
    
    	}
    
    	public void color() {
    		car.color();
    		System.out.println("白色");
    	}
    
    	public void size() {
    		car.size();
    		System.out.println("大空间");
    	}
    }
    

      

    package shejimoshi.zhuangshiqi.car;
    
    import shejimoshi.zhuangshiqi.car.juticar.oldcar;
    import shejimoshi.zhuangshiqi.car.zhuangshi.bmw;
    import shejimoshi.zhuangshiqi.car.zhuangshi.zhuangshi;
    //测试类
    public class testcar {
     public static void main(String[] args) {
    	Car car=new oldcar();
    	car.color();
    	car.size();
    	zhuangshi BMW=new bmw(car);
    	BMW.color();
    	BMW.size();
    }
    }
    

      

  • 相关阅读:
    C#文件操作
    C#Web编程
    WMsg参数常量值
    IIS管理网站浏览
    课程视频网址
    CSS 学习质料
    Centos镜像使用帮助
    apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104))
    How to Configure Nginx for Optimized Performance
    luarocks install with lua5.1 and luajit to install lapis
  • 原文地址:https://www.cnblogs.com/ysg520/p/9593431.html
Copyright © 2011-2022 走看看