Servlet
public class BusinessAServlet extends HttpServlet {
//servlet拥有接口类型的businessA属性,具体实现由实现类来处理,如果想更换实现类,改这一行就可以啦
private BusinessAServiceInterface businessA = new BusinessAServiceImpl();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//业务逻辑处理
businessA.businessAServiceTest1();
businessA.businessAServiceTest2();
businessA.businessAServiceTest3();
}
}
service 层
具体业务接口层
public interface BusinessAServiceInterface {
public abstract void businessAServiceTest1();
public abstract void businessAServiceTest2();
public abstract void businessAServiceTest3();
}
具体业务实现层
public class BusinessAServiceImpl implements BusinessAServiceInterface{
//拥有接口类型的Dao,如果以后想更换实现类,改这一行就可以了
private BusinessADaoInterface businessADaoInterface = new BusinessADaoImpl();
@Override
public void businessAServiceTest1() {
System.out.println("businessAServiceTest1");
//Dao删除数据
businessADaoInterface.delete(1);
}
@Override
public void businessAServiceTest2() {
System.out.println("businessAServiceTest2");
}
@Override
public void businessAServiceTest3() {
System.out.println("businessAServiceTest3");
}
}
Dao层
具体Dao接口层
public interface BusinessADaoInterface {
public abstract Object get(Integer id);
public abstract void delete(Integer id);
}
具体Dao实现层
public class BusinessADaoImpl implements BusinessADaoInterface {
@Override
public Object get(Integer id) {
return null;
}
@Override
public void delete(Integer id) {
}
}