int main(void) { DVDFactory dvdFactory; CDFactory cdFactory; AbstractDisk *dvd = dvdFactory.create(); AbstractDisk *cd = cdFactory.create(); dvd->play(); cd->play(); return 0; }
bool do_test(const string &pos_file, const string &geo_file, const string &cd_type) { bool ret_val = true; vector<vector <double> > position; vector<double> geo; if (!load_positions(pos_file, position)) { ret_val = false; cerr << "Error: while reading positions file\n"; } if (!load_geometry(geo_file, geo)) { cout << "Error: while reading geometry file\n"; ret_val = false; } if (ret_val) { cout << "Positions: "; for (unsigned int i = 0; i < position.size(); i++) { cout << i<< ": " << functions::printVector(position[i]) << "\t"; } cout << endl; cout << "Geometry: "; cout << functions::printVector(geo) << endl; cout << "Type: " << cd_type << endl; CDFactory fac; CD *c = fac.create(cd_type); if (c != NULL && c->detectCollision(position, geo)) { cout << "Collision detected in the system\n"; } else if (c != NULL) { cout << "No collisions detected in the system.\n"; } else { cout << "Could not create the collision detector\n"; } } return ret_val; }