Service 层和 Dao 层有必要为每个类都加上接口吗?
点击上方“码农突围”,马上关注
这里是码农充电第一站,回复“666”,获取一份专属大礼包
真爱,请设置“星标”或点个“在看
不需要接口的理由
可以在尚未实现具体Service逻辑的情况下编写上层代码,如Controller对Service的调用 Spring默认是基于动态代理实现AOP的,动态代理需要接口 可以对Service进行多实现
- 先在Controller层编写逻辑,遇到需要委托Service调用的地方,直接先写出调用代码。优先完成Controller层的流程
- 然后使用IDE的自动补全,对刚才调用下层的代码生成对应的类和方法,在里面添加TODO
- 等所有的类和方法都补全了,再基于TODO,按照上面的流程去一个个的完善逻辑。
项目结构与接口实现
Controller Service Dao
Controller Service ----接口在一个包中 impl ---实现在另一个包里 Dao
Controller Service ---- 接口在一个包中 impl ---实现在另一个包里 impl2 ---新实现在另一个包里 Dao
Controller Service ---- 接口在一个包中 impl ---实现在另一个包里 Service2 impl2 ---新实现在另一个包里 Dao
Controller Service --- 接口模块 ServiceImpl impl ---实现在另一个包里 ServiceImpl2 impl2 ---新实现在另一个包里 Dao
Controller Service --- 接口模块 ServiceImpl impl ---实现在另一个包 ServiceImpl2 impl ---新实现和老实现在相同的包中 Dao
Controller Service1 --- 老实现 Service2 --- 新实现 Dao
不使用接口的缺点
总结
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。