interface-design

C++ DAL - Return Reference or Populate Passed In Reference

橙三吉。 提交于 2019-11-30 22:29:52
[EDIT 1 - added third pointer syntax (Thanks Alex)] Which method would you prefer for a DAL and why out of: Car& DAL::loadCar(int id) {} bool DAL::loadCar(int id, Car& car) {} Car* DAL::loadCar(int id) {} If unable to find the car first method returns null, second method returns false. The second method would create a Car object on the heap and populate with data queried from the database. Presumably (my C++ is very rusty) that would mean code along the lines of: Car& DAL::loadCar(int id) { Car *carPtr = new Car(); Car &car= *carPtr; car.setModel(/* value from database */); car.setEngineSize(/

C++ DAL - Return Reference or Populate Passed In Reference

孤人 提交于 2019-11-30 05:42:34
问题 [EDIT 1 - added third pointer syntax (Thanks Alex)] Which method would you prefer for a DAL and why out of: Car& DAL::loadCar(int id) {} bool DAL::loadCar(int id, Car& car) {} Car* DAL::loadCar(int id) {} If unable to find the car first method returns null, second method returns false. The second method would create a Car object on the heap and populate with data queried from the database. Presumably (my C++ is very rusty) that would mean code along the lines of: Car& DAL::loadCar(int id) {

Is there a pattern for initializing objects created via a DI container

走远了吗. 提交于 2019-11-26 01:19:40
问题 I am trying to get Unity to manage the creation of my objects and I want to have some initialization parameters that are not known until run-time: At the moment the only way I could think of the way to do it is to have an Init method on the interface. interface IMyIntf { void Initialize(string runTimeParam); string RunTimeParam { get; } } Then to use it (in Unity) I would do this: var IMyIntf = unityContainer.Resolve<IMyIntf>(); IMyIntf.Initialize(\"somevalue\"); In this scenario runTimeParam