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;
    }
  • 相关阅读:
    shell eval命令
    嘟嘟嘟
    07 linkextractor的基本用法
    rabbitmq消息队列
    5. 哨兵集群
    4.主从同步
    3. redis持久化存储
    2. redis 安全
    1.redis基础
    06. scrapy的Request对象
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2560285.html
Copyright © 2011-2022 走看看