Click here to Skip to main content
15,846,899 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
AnswerRe: code organisation Pin
Richard MacCutchan4-Feb-22 5:56
mveRichard MacCutchan4-Feb-22 5:56 
GeneralRe: code organisation Pin
Calin Negru4-Feb-22 9:48
Calin Negru4-Feb-22 9:48 
GeneralRe: code organisation Pin
jschell17-Feb-22 12:12
jschell17-Feb-22 12:12 
GeneralRe: code organisation Pin
Calin Negru19-Feb-22 2:39
Calin Negru19-Feb-22 2:39 
GeneralRe: code organisation Pin
jeron119-Feb-22 8:03
jeron119-Feb-22 8:03 
GeneralRe: code organisation Pin
Calin Negru19-Feb-22 9:10
Calin Negru19-Feb-22 9:10 
GeneralRe: code organisation Pin
Richard MacCutchan19-Feb-22 22:44
mveRichard MacCutchan19-Feb-22 22:44 
GeneralRe: code organisation Pin
Calin Negru25-Feb-22 10:41
Calin Negru25-Feb-22 10:41 
What is the default approach for creating objects using a factory? When one is creating several objects of the same class using a factory is the factory class retaining the objects as an array/std container and returning through a function a pointer to the object that has been created (which can be stored into an array/container outside the factory class)?

this is code for creating a single object
#include <iostream> 
using namespace std; 

class Vehicle { 
public: 
    virtual void printVehicle() = 0; 
    static Vehicle* Create(VehicleType type); 
}; 
class TwoWheeler : public Vehicle { 
public: 
    void printVehicle() { 
        cout << "I am two wheeler" << endl; 
    } 
}; 

  
Vehicle* Vehicle::Create() { 
        return new TwoWheeler(); 
} 
  
// Client class 
class Client { 
public: 
  
   
    Client() 
    { 
        
    } 

    ~Client() { 
        if (pVehicle) { 
            delete[] pVehicle; 
            pVehicle = NULL; 
        } 
    } 
    void BuildVehicle()
    {
     pVehicle = Vehicle::Create(); 
    }
    Vehicle* getVehicle()  { 
        return pVehicle; 
    } 
  
private: 
    Vehicle *pVehicle; 
}; 
  
 
int main() { 
    Client *pClient = new Client(); 
    pClient->BuildVechicle();
    Vehicle * pVehicle = pClient->getVehicle(); 
    pVehicle->printVehicle(); 
    return 0; 
} 


how should the modified version of main() look like if you want more than one vehicle to be created
GeneralRe: code organisation Pin
Richard MacCutchan25-Feb-22 23:17
mveRichard MacCutchan25-Feb-22 23:17 
GeneralRe: code organisation Pin
Calin Negru26-Feb-22 1:14
Calin Negru26-Feb-22 1:14 
GeneralRe: code organisation Pin
Richard MacCutchan26-Feb-22 2:03
mveRichard MacCutchan26-Feb-22 2:03 
GeneralRe: code organisation Pin
Snesh Prajapati26-Feb-22 6:04
professionalSnesh Prajapati26-Feb-22 6:04 
AnswerRe: code organisation Pin
Greg Utas4-Feb-22 6:52
professionalGreg Utas4-Feb-22 6:52 
AnswerRe: code organisation Pin
jschell17-Feb-22 12:21
jschell17-Feb-22 12:21 
QuestionBest Way To Solve This? Pin
Kevin Marois11-Jan-22 7:32
professionalKevin Marois11-Jan-22 7:32 
AnswerRe: Best Way To Solve This? Pin
englebart15-Feb-22 17:54
professionalenglebart15-Feb-22 17:54 
QuestionWould it be possible to build megastructures like the Forerunners in <i>Halo</i>? Pin
oofalladeez34328-Dec-21 10:32
professionaloofalladeez34328-Dec-21 10:32 
AnswerRe: Would it be possible to build megastructures like the Forerunners in <i>Halo</i>? Pin
Dave Kreskowiak28-Dec-21 12:02
mveDave Kreskowiak28-Dec-21 12:02 
GeneralRe: Would it be possible to build megastructures like the Forerunners in <i>Halo</i>? Pin
jschell30-Dec-21 8:38
jschell30-Dec-21 8:38 
GeneralRe: Would it be possible to build megastructures like the Forerunners in <i>Halo</i>? Pin
Dave Kreskowiak30-Dec-21 8:39
mveDave Kreskowiak30-Dec-21 8:39 
GeneralRe: Would it be possible to build megastructures like the Forerunners in <i>Halo</i>? Pin
jschell30-Dec-21 8:44
jschell30-Dec-21 8:44 
GeneralRe: Would it be possible to build megastructures like the Forerunners in <i>Halo</i>? Pin
Dave Kreskowiak30-Dec-21 8:46
mveDave Kreskowiak30-Dec-21 8:46 
GeneralRe: Would it be possible to build megastructures like the Forerunners in <i>Halo</i>? Pin
jschell30-Dec-21 8:50
jschell30-Dec-21 8:50 
GeneralRe: Would it be possible to build megastructures like the Forerunners in <i>Halo</i>? Pin
Dave Kreskowiak30-Dec-21 9:01
mveDave Kreskowiak30-Dec-21 9:01 
GeneralRe: Would it be possible to build megastructures like the Forerunners in <i>Halo</i>? Pin
jschell30-Dec-21 9:12
jschell30-Dec-21 9:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.