DAO还是PDA?!

lusterf 05-09-22

分离persistence logic from business logic 很重要.以下两种实现究竟那个好?!

PDO中:
public interface Entity{
public interface EntityDBManager{
public void insert(Entity entity);
public void save(Entity entity);
.........//other method
}
..............//other method you want
}
public class EntityImpl{
private static Entity.EntityDBManager manager = null;
public static Entity.EntityDBManager getManager () {
return EntityDBManager.manager;
}
public static void setManager ( Entity.EntityDBManager
manager ) {
EntityDBManager.manager = manager;
}
......
//properties and methods
private Object XXX;
public void setXXX(){}
public XXX getXXX(){return XXX;}
}
.....
public class EntityDBManagerImpl implements Entity.EntityDBManager{
//implement methos
....
....

}
DAO 中:
(太熟了,省略....)
.................................................

//调用中可能是
EntityDBManagerImpl manager = ...
Entity entity= new Entity ("name");
etity.setCatManager(manager );
etity.getManager().save(entity);
但在DAO中也可以这样 :
//此处的manager不和上处同
EntityDBManagerImpl manager = ...
Entity entity = new Entity("name");
EntityDBManagerImpl .save(cat);
是否这样简洁些?!