I recently inherited a project that includes and assessment portion, where you are asked a series of T/F questions and the responses are saved to a database. The requirements have now changed and I need to retrieve those answers later in the process. In other places in this project the classes have a call to a data access object (DAO) in each GET - that seems clunky and slow to me since that is a lot of DB server trips if I have to get 20-30 answers. It seems better to me to have one call to the DB and then fill all the properties in memory.
Assuming I have a class like this
public class Assessment
{
// Property Variables like private bool _needSearchAssistance;
// Accessor Methods - Typical Get{} Set{}
// Constructor
public Assessment()
{
}
public void SendResultsEmail(EmailAddress email)
{
// Typical SMTP stuff
}
public void Save(int ParticipantId)
{
//Instantiate DAO and save to DB
}
}
Does it make more sense to use an overloaded constructor like:
public Assessment(int ParticipantId)
{
//Instantiate DAO and get values to fill props.
}
Or leave the constructor alone and create a function like
public void LoadFromDb(int ParticipantId)
{
/Instantiate DAO and get values to fill props.
}
If you use the function approach, is there a typical or standard 'naming convention' for this type of function. So far LoadFromDb is the best I can think of.