论坛首页 Java企业应用论坛

PDO优于DAO?

浏览 4083 次
锁定老帖子 主题:PDO优于DAO?
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2005-09-21  
DAO
分离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);
是否这样简洁些?!
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics