vendredi 31 août 2018

It's Mediator Pattern. Airport [on hold]

#include<iostream>
#include<vector>
#include<string>
using namespace std;

class AFlight;
class Flight747;
class Flight1011;
class Flight112;
class Flight7E7;

class ATCMediator /// this is air traffic controller, which i use as a mediator in this case.../// 
{
protected:
    vector<AFlight*> flight;
public:
    ATCMediator() = default;
    void Add(AFlight*f) {
        flight.push_back(f);
    }
    void Send(string msg) {
        //if(SetDistance()<500)
        for (int i = 0; i < flight.size(); i++)

            flight[i]->Notify(msg);   //  this is where i get "use of underfined type'Flight' "..... Eroor C2027.//

    }

    friend class AFlight;
    friend class Flight747;
    friend class Flight1011;
    friend class Flight112;
    friend class Flight7E7;
};

class AFlight  // this is virtual class that i use for other planes types.///
{
protected:
    ATCMediator *m;

public:
    //AFlight() {};
    virtual void Send() = 0;
    virtual int SetDistance() = 0;
    virtual void Notify(string msg) = 0;

};

class Flight747:public AFlight
{
protected:
    string name;
    int distance;
public:
    Flight747(ATCMediator *m, int distance) { this->distance = distance; this->m = m; };
    void Send() {
        m->Send("");
    }
    int SetDistance() {
        return distance;
    }


    void Notify(string msg) 
    { 
        cout << msg << endl;
    };
};

class Flight1011 :public AFlight
{
protected:
    string name;
    int distance;
public:
    Flight1011(ATCMediator *m, int distance) { this->distance = distance; this->m = m; };
    void Send() {
        m->Send("");
    }
    int SetDistance() {
        return distance;
    }


    void Notify(string msg)
    {
        cout << msg << endl;
    };
};

class Flight112:public AFlight
{
protected:
    string name;
    int distance;
public:
    Flight112(ATCMediator *m, int distance) { this->distance = distance; this->m = m; };
    void Send() {
        m->Send("");
    }
    int SetDistance() {
        return distance;
    }


    void Notify(string msg)
    {
        cout << msg << endl;
    };
};

class Flight7E7:public AFlight
{
protected:
    string name;
    int distance;
public:
    Flight7E7(ATCMediator *m, int distance) { this->distance = distance; this->m = m; };
    void Send() {
        m->Send("");
    }
    int SetDistance() {
        return distance;
    }


    void Notify(string msg)
    {
        cout << msg << endl;
    };
};

void main()
{
    ATCMediator *M = new ATCMediator();
    AFlight *f1 = new Flight747(M, 345);




    system("pause");
}

Would be kindly appreciated if someone can tell me how to fix this issue and continue on my project... thank you in advance .

It's my patter mediator graph

This was the first idea, of making it like this, but then i switched to make more like first picture.

Air traffic controller , in the airport is a mediator of all planes that are in a distance of 500 kilometers of the airport. Mediator can receive massages and can send it to specific aircraft or send it to all of them at once. When Plane try to take off, it send massage to mediator and mediator send it to all that that plane is taking off. If it can or can not take off then its will be simply bool operator.Pretty much is for landing, mediator is in control of all planes around the airport. and Sometimes plane want to contact the plane next the him or something like that , it send massage to mediator and mediator send it only to specific plane . But i got stuck on this error. please help me , so i can move on with this project.

Aucun commentaire:

Enregistrer un commentaire