我在多个Web应用程序中实现了我认为相当不错的MVC模式,但自从加入crackoverflow以来,我发现我的最初定义可能有点过于简单化了,因此我真的想要一些关于数据访问层和模型或领域层之间差异的澄清。
为了背景信息,我目前使用实现单个记录的CRUD函数以及返回一个对象的get()函数的数据访问对象,该对象使我能够迭代满足get()函数条件的所有对象。
这些数据访问对象直接从包含我的业务逻辑的控制器脚本中引用。
如果有影响的话,我正在使用PHP和MySQL,但对于其他编程语言的建议也感兴趣。
更新: 更具体地说,我有一个名为“user”的表(这里的约定是单数表名),其中包含诸如电子邮件地址、活动状态、用户名、密码、所属公司等信息。这个基本对象在代码中看起来像这样:
class User implements DataAccessObject
{
protected $user_id;
protected $email;
protected $username;
protected $password;
protected $company_id;
protected $active // Bool that holds either a 0 or 1
public function __construct ( $user_id ) // Uses Primary Key to know which record to construct
{
$sql = //Sql to get this information from the database.
// Code necessary to assign member variables their values from the query.
}
public function insert(){}
public function update(){}
public function delete(){}
public static function get($filters, $orderVals, $limit){}
// An object such as user might also contain the following function definition
public static function login($username, $password){}
}
听起来我可能把DAO层和Model层混合成了一个简化的形式,将真实世界类型函数(例如用户登录)与数据访问函数结合在一起。