Rewrite the code in c++ using Factory Method. The goal is to remove the
main function’s dependency on the concrete classes, such as FlyToSchool,
#ifndef FLYTOSCHOOL_H
#define FLYTOSCHOOL_H
#include <iostream>
#include "GoToSchool.hpp"
using namespace std;
class FlyToSchool:public GoToSchool {
void takeTransit() { cout << "We are taking a flight." << endl; }
void arrive() { cout << "After 2 hours, we arrive." << endl; }
};
#endif
#ifndef FLYTOSCHOOL_H
#define FLYTOSCHOOL_H
#include <iostream>
#include "GoToSchool.hpp"
using namespace std;
class FlyToSchool:public GoToSchool {
public:
void takeTransit() {
cout << "We are taking a flight." << endl;
}
void arrive() {
cout << "After 2 hours, we arrive." << endl;
}
};
Comments
Leave a comment