通过查看Zend Quickstart教程中域对象的示例以及考虑DAO / VO模式的其他示例,它们似乎非常相似。
我们可以得出这样的结论,即说“值对象”与说“域对象”是相同的吗?
如果不是,请解释它们之间的区别。
其中一个的功能是什么,另一个的功能是什么?
我之所以问这个问题,是因为它们都由getter和setter组成,除此之外没有任何东西。看起来它们执行相同的功能...
更新:
因此,Zend Framework Quick Tutorial文档称其为域对象:
我们可以得出这样的结论,即说“值对象”与说“域对象”是相同的吗?
如果不是,请解释它们之间的区别。
其中一个的功能是什么,另一个的功能是什么?
我之所以问这个问题,是因为它们都由getter和setter组成,除此之外没有任何东西。看起来它们执行相同的功能...
更新:
因此,Zend Framework Quick Tutorial文档称其为域对象:
// application/models/Guestbook.php
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;
}
}
1) 严格来说,我们面对的是“贫血领域对象”吗?
2) 它之所以被称为“领域对象”,仅仅是因为它包含了领域逻辑吗?
3) 如果是这样的话,那么像findBookByAuthor()这样的方法所在的映射器也在处理领域逻辑,对吗?它们也可以被视为领域对象吗?
非常感谢。