Site Tools


c_adapter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c_adapter [2013/03/01 17:47] (current)
konovalov created
Line 1: Line 1:
 +    #include <​QtCore/​QCoreApplication>​
 +    #include "​adapter.h"​
 +    ​
 +    int main(int argc, char *argv[])
 +    {
 +        QCoreApplication a(argc, argv);
 +    ​
 +        Transport* arrTrans[2];​
 +        arrTrans[0] = new Car;
 +        arrTrans[1] = new AdapterToyTransport(new Skate);
 +    ​
 +        for(short i = 0; i < 2; i++){
 +            arrTrans[i]->​raidToWork();​
 +            arrTrans[i]->​onMagnitola();​
 +        }
 +    ​
 +        return 0;
 +    }
 +
 +
 +    #ifndef ADAPTER_H
 +    #define ADAPTER_H
 +    ​
 +    class Transport{
 +    public:
 +        virtual void raidToWork() = 0;
 +        virtual void onMagnitola() = 0;
 +    };
 +    ​
 +    class Car : public Transport{
 +        void raidToWork();​
 +        void onMagnitola();​
 +    };
 +    ​
 +    class Toy{
 +    public:
 +        virtual void gameWithToy() = 0;
 +    };
 +    ​
 +    class Skate : public Toy{
 +    public:
 +        void gameWithToy();​
 +    };
 +    ​
 +    class AdapterToyTransport : public Transport
 +    {
 +        Toy* toy;
 +    public:
 +        AdapterToyTransport(Toy*);​
 +        void raidToWork();​
 +        void onMagnitola();​
 +    };
 +    ​
 +    #endif // ADAPTER_H
 +
 +
 +    #include "​adapter.h"​
 +    #include <​iostream>​
 +    using namespace std;
 +    ​
 +    void Car::​raidToWork(){
 +        cout << "Car: sit in car and drive to work." << endl;
 +    }
 +    ​
 +    void Car::​onMagnitola(){
 +        cout << "​inCar:​ on magnitola"​ << endl;
 +    }
 +    ​
 +    void Skate::​gameWithToy(){
 +        cout << "​inSkate:​ do Flip" << endl;
 +    }
 +    ​
 +    ​
 +    AdapterToyTransport::​AdapterToyTransport(Toy* inToy){
 +        this->​toy = inToy;
 +    }
 +    ​
 +    void AdapterToyTransport::​raidToWork(){
 +        cout << "​inSkate:​ catch car and raid how tail" << endl;
 +    }
 +    ​
 +    void AdapterToyTransport::​onMagnitola(){
 +        cout << "​inSkate:​ get headphones and listen player"​ << endl;
 +    }
  
c_adapter.txt ยท Last modified: 2013/03/01 17:47 by konovalov

Page Tools