Data objects often require special processing. open and closing of database, or transactions. reading / writing of files. catching sql exceptions, marshalling data, and other access technicalities like these. You don't want to be dealing with this stuff all over the place so you try to put it into a single package.
That is all.
As I stated _dnoyeB, I was looking for something that would have an example with a layman's explanation, as I seem to have an easier time understanding when it's not at such a coceptual leve. It seems as though I phrased it incorrectly or I am simply not explaining what I am looking for. I will award you the dollar and continue my search elsewhere. I guess I was trying to see if there is only one particular way to do it (to follow standards) or if it was just the concept of seperating the source of the data from the rest of the application.
Thanks anyways.
Well I gave you the simple explanation first but you wanted something more complcated so I gave you the link. Can't do more than that.
DAO is not a special way of doing a thing. Its a natural way to do it in OO. I can't think of any other way to design software that uses a datastore of some sort without a DAO layer.
I think that clarifies my question even more. I was just ensuring that DAO simply refers to encapsulating the data so that the application does not have to be aware of it's source. I guess I just wanted to make sure that is all the concept referrred and that I wasn't missing anything.
thanks for the quick replies as well.
Here is an example.
This is from one of my DAOs
class DBGraphic extends DBObject {
void setLocation(Point p) throws DatasourceException {
try {
String qstring = "UPDATE containableGraphics SET " + "X = " + p.x + "," + "Y = " + p.y + " " + "WHERE ID = " + getID() + " ;";
int records = getDatabase().executeUpdate(qstring);
if(records == 0){
throw new DatasourceException("Failed to update location");
}
assert records < 2 :"Improper number of records updated";
}
catch (SQLException sqle) {
throw new DatasourceException(sqle);
}
}
}
And this is from one of my business objects that uses it sorta
class WADBaseModel implements IBaseModel {
public final void setLocation(Point p) throws WADException{
checkDisposed();
checkDeleted();
if (!this.location.equals(p)){
try {
this.graphic.setLocation(p);
this.location = new Point(p);
firePhysicalPropertyChange(ModelProperties.LOCATION, new Point(p));
}
catch (DatasourceException e) {
throw new WADException("Unable to modify dao",e);
}
}
}
}