Topic: DAO设计,测试的问题 |
Print this page |
1.DAO设计,测试的问题 | Copy to clipboard |
Posted by: gaoxt1983 Posted on: 2006-11-24 08:52 DAO真的有必要设计成接口吗?还有Service,为什么啊?别告诉我是为了以后换实现方便,有多少直接换实现的情况…… java 代码 public interface LoginService { public User getUser(String userName,String password) throws LoginException; public setLoginDao(LoginDao arg); public setIpBannerDao(IpBannerDao arg); } 比如: java 代码 public class LoginServiceImpl implements LoginService { public User login(String userName,String password) throws LoginException { User user=userDao.getUser(userName,password); if(user==null) { throw new LoginException("你丫不是输错用户名就是记错密码了"); } if(ipBannerDao.checkUser(user)==false) { throw new LoginException("靠,被banner了还敢来,不想活了?"); } return user; } } 那么,把DAO,Service写成接口的好处是什么? 现在,我想测试LoginService,那么我需要模拟实现两个DAO,写两个对应的Mock,还有一个testCase,可是,如果DAO多了的话,那么,我们就需要为一个Service些5,6个DAO,真的有这个必要吗? 还有,如何写这些Mock Dao?测试数据怎么注入DAO中? |
2.Re:DAO设计,测试的问题 [Re: gaoxt1983] | Copy to clipboard |
Posted by: zhangzhaofeng Posted on: 2007-01-26 15:33 建议接口和抽象类结合使用 |
3.Re:DAO设计,测试的问题 [Re: gaoxt1983] | Copy to clipboard |
Posted by: Jacob53 Posted on: 2008-02-12 18:00 在项目前期,可以先把接口写出来,然后用这些接口为程序建框架,最后用实类把内容填进去。 当然这是二十世纪的应用程序式设计方法,虽然现在还有很多顽固分子用这种方法,但现在的MVC式的设计方法已经不大需要接口。 |
4.Re:DAO设计,测试的问题 [Re: gaoxt1983] | Copy to clipboard |
Posted by: floater Posted on: 2008-04-19 09:30 depends on your service. For login service, my experience is yes, you need that, , if you have tens of ways to verify them, user/password, nt login, digital certs, finger prints, face recognition, etc... I have a dao interface so that users can specify in the runtime to output the result to console, database, file, special cache, or downstream targets. Most important thing is that you have to think hard about the interface, the data you send across this interface. Using a Map on the interface is almost for sure is a bad idea because it makes the interface almost invisible at all. For example, User load(int userId); or load(User user); which one is better? insertUser(int userId, String password, String name); or insert(User); which one is better? int getUserId(); should this be on the interface? How about this: User.load() and how about load(User[] users) |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |