1
我有我的業務對象的存儲庫,我需要根據數據創建不同的對象。我應該直接在repo中創建它們還是將其移動到其他地方 - 工廠或業務邏輯層中的某個類?我應該在哪裏創建對象?庫?廠?
/**
* @returns Applier
*/
class ApplierRepository implements IApplierRepositoryInterface {
//some code
public function find($id) {
$data = $this->findBySql($id);
//Is it a business logic?
if($data['profile_id'] != null)
$object = new ProfileApplier();
if($data['user_id'] != null) {
$user = $this->userRepository->find($data['user_id']);
$object = new UserApplier($user);
}
//...
return $object;
}
}
非常感謝!這就是我一直在尋找的。 –
不客氣! –