zoukankan      html  css  js  c++  java
  • 建造者模式(C++)

    #include <iostream>
    using namespace std;
    
    class buildcomputer
    {
    public:
        buildcomputer(){}
        virtual ~buildcomputer(){}
        virtual void buildmouse()=0;
        virtual void buildmointor()=0;
        virtual void buildkeyboard()=0;
        virtual void buildhost()=0;
    };
    
    class winbuildcomputer : public buildcomputer
    {
    public:
        winbuildcomputer(){}
        virtual ~winbuildcomputer(){}
        void buildmouse(){cout<<"build win mouse"<<endl;}
        void buildmointor(){cout<<"build win mointor"<<endl;}
        void buildkeyboard(){cout<<"build win keyboard"<<endl;}
        void buildhost(){cout<<"build win host"<<endl;}
    };
    
    class macbuildcomputer : public buildcomputer
    {
    public:
        macbuildcomputer(){}
        virtual ~macbuildcomputer(){}
        void buildmouse(){cout<<"build mac mouse"<<endl;}
        void buildmointor(){cout<<"build mac mointor"<<endl;}
        void buildkeyboard(){cout<<"build mac keyboard"<<endl;}
        void buildhost(){cout<<"build mac host"<<endl;}
    };
    
    class director
    {
    private:
        buildcomputer *instance;
    
    public:
        director(buildcomputer *bd)
            :instance(bd){}
        virtual ~director(){}
        void creator()
        {
            instance->buildmouse();
            instance->buildmointor();
            instance->buildkeyboard();
            instance->buildhost();
        }
    };
    
    int main()
    {
        buildcomputer *p=new macbuildcomputer;
        director *dc=new director(p);
        dc->creator();
        delete dc;
        delete p;
    
        p=new winbuildcomputer;
        dc=new director(p);            
        dc->creator();
        delete dc;
        delete p;
    
        system("pause");
        return 0;
    }
  • 相关阅读:
    APP高级抓包
    Linux使用日志
    ffmpeg使用记录
    win7 远程连接ubuntu
    v-2-r-a-y使用
    adb
    golang mysql 模糊查询
    交互式批量删除指定目录下指定类型文件
    golang打包和部署到centos7
    Nginx unknown directive ""
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2560285.html
Copyright © 2011-2022 走看看