Questions tagged «data-access-layer»

10
django中业务逻辑和数据访问的分离
我正在Django中编写一个项目,并且看到80%的代码在file中models.py。这段代码令人困惑,并且在一段时间之后,我不再了解实际发生的事情。 这是困扰我的事情: 我发现模型级别(应该只负责处理数据库中的数据)在发送电子邮件,使用API​​到其他服务等方面也很丑陋。 另外,我发现在视图中放置业务逻辑也是不可接受的,因为这样很难控制。例如,在我的应用程序中,至少有三种方法来创建的新实例User,但从技术上讲,它应统一创建它们。 我并不总是注意到模型的方法和属性何时变得不确定,以及何时出现副作用。 这是一个简单的例子。首先,User模型是这样的: class User(db.Models): def get_present_name(self): return self.name or 'Anonymous' def activate(self): self.status = 'activated' self.save() 随着时间的流逝,它变成了: class User(db.Models): def get_present_name(self): # property became non-deterministic in terms of database # data is taken from another service by api return remote_api.request_user_name(self.uid) or 'Anonymous' def activate(self): # method …


12
存储库模式与DAL
它们是一样的吗?刚看完Rob Connery的Storefront教程,它们似乎是类似的技术。我的意思是,当我实现DAL对象时,我具有GetStuff,Add / Delete等方法,并且总是先编写接口,以便以后可以切换db。 我会感到困惑吗?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.