C ++ DAL - return link or padding in link

[EDIT 1 - added third pointer syntax (thanks Alex)]

Which method do you prefer for DAL and why from it:

Car& DAL::loadCar(int id) {}
bool DAL::loadCar(int id, Car& car) {}
Car* DAL::loadCar(int id) {}

If the first method of the car cannot be found, null is returned; the second method returns false.

The second method would create a Car object on the heap and populate the data requested from the database. Presumably (my C ++ is very rusty), which will mean the code line by line:

Car& DAL::loadCar(int id)
{
    Car *carPtr = new Car();
    Car &car= *carPtr;
    car.setModel(/* value from database */);
    car.setEngineSize(/* value from database */);
    // etc
    return car;
}

thanks

+5
source share
2 answers

, , . , new'd. , , , . PLUS, -

Car myCar = dal.loadCar( id );

.

, .

: , , , .. DAL, . .. DAL Car, .

Edit2: . , , , .

Car DAL::loadCar(int id);

, .

, , , "", (, , ), .

+5

, Car * LoadCar(), NULL, . , ( ), .

+4

All Articles