I'm using a basic 3-tier design. For flexibility (and testing) purposes, I wanted the data layer to be abstract and specify the concrete class in my code. But, how should I pass this along to my business objects. Here's an example (pseudo code):
abstract class IDataLayer
{
PersonData GetPerson(int); //PersonData would be a row of data from a table for example
JobData[] GetJobs(int);
void UpdatePerson(PersonData);
}
class ConcreteDataLayerSQL : IDataLayer
{
...
}
class ConcreteDataLayerXML : IDataLayer
{
...
}
class PersonBAL
{
void PersonBAL(personId)
{
//What goes here?
}
JobBAL[] GetJobs()
{
//What goes here?
}
}
class Program
{
static void Main()
{
person = new PersonBAL(1);
}
}
So the problem is, how does PersonBAL know which ConcreteDataLayer to use? I'm thinking between a few options:
1: pass the concrete data layer to person. This becomes a pain when you start adding new classes that need to interact with the data layer (something like new PersonBAL(IDataLayer, int), then new JobBAL(IDataLayer, int), etc etc)
2: Create a static object that holds which data layer to use (Read: global variable)
Any other ideas?