Can you give me an example of this? Looking for a simple,simple class in
the bussiness layer and an another one in the data layer with code that
uses these. I believe you, but i am having problem invisioning this.
thanks,
I have a framework that allows me to store objects in a database, but I
don't want the people who develop the business objects to have to know
anything about SQL or any other database stuff.
So I declare an interface or "contract" that I can talk to in a totally
database independent way.
Here is a simplified example :
public interface IObjectSpace
{
bool StoreObject(object obj);
bool DeleteObject(object obj);
object RetrieveObject(int id);
IList RetrieveCollection(Type objectType);
...
}
Now I can call this code like this :
{
IObjectSpace os = new SQLServerObjectSpace();
IList list = os.RetrieveCollection(typeof(Customer));
int custId = ((Customer) list[0]).Id;
Customer cust = (Customer) os.RetrieveObject(custId);
cust.Address = "123 This Street";
os.StoreObject(cust);
}
This code assumes that we are creating an instance of a class that knows how
to manage converting objects to/from SQLServer tables.
However, by just changing the first line of that code example, and assuming
I have another class that represents a mechanism for converting objects
t/from XML, I can work with a test "database" which is a simple XML storage
mechanism.
{
IObjectSpace os = new TestXMLObjectSpace();
IList list = os.RetrieveCollection(typeof(Customer));
int custId = ((Customer) list[0]).Id;
Customer cust = (Customer) os.RetrieveObject(custId);
cust.Address = "123 This Street";
os.StoreObject(cust);
}
Notice that it is only the first line of the example that has changed; all
the rest of the code remains identical. This is because I have defined a
contract that I expect any class that implements IObjectSpace to fulfil.
Now I can design my business classes and test them against my own XML test
object space, whilst someone else goes off and writes the SQLServer version.
When they have finished all I have to change is that one line of code that
creates the actual object space instance.
Does that help ?
Joanna