zoukankan      html  css  js  c++  java
  • 装饰模式,制作一个蛋糕java

    import java.text.DecimalFormat;
    
     //抽象组件组件
    interface mkcake
    {
        public void cake();
    }
    class  Cake implements mkcake
    {
    
        @Override
        public void cake() {
            // TODO Auto-generated method stub
            System.out.println("一个成型蛋糕");
            
        }
         
    }
    //装饰接口
    abstract class Decorator implements mkcake
    {
        mkcake m;
        
          public Decorator(mkcake m)
          {
              this.m=m;
          }
        
        }
    class AddMilk extends Decorator
    {
        public AddMilk(mkcake m)
        {
            super(m);
        }
    
        @Override
        public void cake() {
            // TODO Auto-generated method stub
            m.cake();
            System.out.println("加了牛奶");
            
        }
    
        
        
    }
    class AddEgg extends Decorator
    {
        public AddEgg(mkcake m)
        {
            super(m);
        }
    
        @Override
        public void cake() {
            // TODO Auto-generated method stub
            m.cake();
            System.out.println("加了鸡蛋");
            
        }
    
        
        
    }
    
    
    
    
    public class 装饰模式 {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            //开始制作蛋糕
            mkcake c=new Cake();
            mkcake m=new AddMilk(new AddEgg(new Cake()));
            m.cake();
    
        }
    
    }
  • 相关阅读:
    Dialog对话框
    Intent的七大属性
    Activity启动模式
    Android知识体系
    Activity生命周期
    Intent实现页面跳转和传值
    Android超链接
    上传文件
    XMLSAX解析
    XmlPull
  • 原文地址:https://www.cnblogs.com/hansongjiang/p/3854302.html
Copyright © 2011-2022 走看看