J2EE DAO层和业务逻辑层的设计

举个例子,比如要做一个学生选课管理系统,数据库中有三张表,分别是STUDENTS,TEACHER,COURSE

DAO层接口设计:
InterfaceStudentDAO
{
publicvoidInsertStudent(Studentstu);

publicvoidremoveStudent(longid);

publicvoidupdateStudent(Studentstu);

publicStudentfindStudent(longid);

/**
*其它DAO方法
**/
}

InterfaceTeacherDAO
{
publicvoidinsertTeacher(Teachertea);

publicvoidremoveTeacher(longid);

publicvoidupdateTeacher(Teachertea);

publicTeacherfindTeacher(longid);

/**
*其它DAO方法
**/
}

InterfaceCourseDAO
{
publicvoidinsertCourse(Coursec);

publicvoidremoveCourse(longid);

publicvoidupdateCourse(Coursec);

publicTeacherfindCourse(longid);

/**
*其它DAO方法
**/
}

业务层接口设计:
InterfaceStudentService
{
publicvoidsaveStudent(Studentstu);

publicvoiddeleteStudent(longid);

publicvoidupdateStudent(Studentstu);

publicStudentgetStudent(longid);

/**
*其它Service方法
**/
}

InterfaceTeacherService
{
publicvoidsaveTeacher(Teachertea);

publicvoiddeleteTeacher(longid);

publicvoidupdateTeacher(Teachertea);

publicTeachergetTeacher(longid);

/**
*其它Service方法
**/
}

InterfaceCourseService
{
publicvoidsaveCourse(Coursec);

publicvoiddeleteCourse(longid);

publicvoidupdateCourse(Coursec);

publicTeachergetCourse(longid);

/**
*其它Service方法
**/
}


将这两层接口写好后分别创建它们的实现类,比如:
publicclassStudentDAOImplimplementsStudentDAO;
publicclassStudentServiceImplimplementsStudentService;

其中StudentServiceImpl中的方法调用StudentDAOImpl中的接口方法

其它类的写法类似不再赘述。

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭