如果Domain Object = Business Object,那么我期待看到像findTaxValues();或searchBooksByAuthor();方法,相反,我通常看到吸气剂和制定者。
1)
这是域对象类吗?
class Application_Model_Guestbook
{
protected $_comment;
protected $_created;
protected $_email;
protected $_id;
public function __construct(array $options = null)
{
if (is_array($options)) {
$this->setOptions($options);
}
}
public function __set($name, $value)
{
$method = 'set' . $name;
if (('mapper' == $name) || !method_exists($this, $method)) {
throw new Exception('Invalid guestbook property');
}
$this->$method($value);
}
public function __get($name)
{
$method = 'get' . $name;
if (('mapper' == $name) || !method_exists($this, $method)) {
throw new Exception('Invalid guestbook property');
}
return $this->$method();
}
public function setOptions(array $options)
{
$methods = get_class_methods($this);
foreach ($options as $key => $value) {
$method = 'set' . ucfirst($key);
if (in_array($method, $methods)) {
$this->$method($value);
}
}
return $this;
}
public function setComment($text)
{
$this->_comment = (string) $text;
return $this;
}
public function getComment()
{
return $this->_comment;
}
public function setEmail($email)
{
$this->_email = (string) $email;
return $this;
}
public function getEmail()
{
return $this->_email;
}
public function setCreated($ts)
{
$this->_created = $ts;
return $this;
}
public function getCreated()
{
return $this->_created;
}
public function setId($id)
{
$this->_id = (int) $id;
return $this;
}
public function getId()
{
return $this->_id;
}
}
更新
2)因为它似乎是一个域对象类:
我很难学习Zend快速入门指南。
到目前为止,这是我的简历:
表数据网关对象 - 这些是表的对象副本,它们应包含与表相关的通用查询。在Zend上,我们将使用它们来执行通用查询,这些查询将通过Zend_Db_Table_Abstract扩展在不同的数据库供应商中运行。那些网关对象会做什么?它们将(通过适配器)连接到我们的数据源(例如:MySQL数据库),采用通用(非数据库特定)方式;
数据映射器对象 - 这些对象可以在我们的数据源和域对象模型之间工作。他们可能会或可能不会使用Gateway访问数据源。他们的工作是,虽然不是将特定的表引用到域(可能需要/可以访问不同的表),但它提供了一种更好地组织数据和相关行为的方法。在这个Zend示例中,我们将使用映射器在域对象和网关对象之间来回移动数据;
如果以上是正确的,那么我仍然错过了这个:
域对象(a.k.a Business Objects) - 那些对象......我没有到达这里......他们与其他人的关系是什么?
我们如何正确定义域对象 - 关于此Gateway / Mapper架构?
答案 0 :(得分:1)
我相信你会让业务经理或类似的东西与域对象混淆。域对象应该是业务实体,因此我要确认您的代码示例是域对象。
编辑|回答您的更新:
域对象是在某些特定业务关注中扮演某个业务角色的实体。如果我不理解Zend的错误定义,“数据映射器对象”可能是“域对象”,但并非在所有情况下都是如此。