Quick question here, that has been haunting me for a while. I referenced it in an older thread of mine, but I didn't get back to the thread due to an insane amount of work that came up. Basically, it has to do with Domain Objects. Say I have a domain object that is a medical Note about a patient visit. This Note can be persisted to the database from data from a form, and retrieved from the database through a Data Mapper. Say it has five properties, i.e. Name, age, problem, etc.
My issue is that I'd like to have one domain object Note, but it comes from two places. So, in the constructor, sometimes I'll be passing a Request object, and sometimes I'll be passing an array from a database query in the Mapper. So, in the former, the controller is filled with:
Code: Select all
$this->name = $argument->getPost('name');
$this->age = $argument->getPost('age')
And in the latter case:
Code: Select all
$this->name = $argument['name'];
$this->age = $argument['age'];
So, I have a conditional that sees whether the passed argument is a Request object or an array, and then use one of the above blocks of code to assign the variables. This, clearly, is messed up.
Basically, how do you assign values to your properties when the domain object which contains them is instantiated by different sources (i.e. db vs. request)?