【发布时间】:2011-08-16 23:41:11
【问题描述】:
如果域对象 = 业务对象,那么我期待看到诸如 findTaxValues(); 之类的东西。或 searchBooksByAuthor();方法,相反,我通常看到 getter 和 setter。
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 数据库);
数据映射对象 - 这些对象将在我们的数据源和我们的领域对象模型之间工作。他们可能会也可能不会使用网关来访问数据源。他们的工作是,虽然不是指特定表,而是指域(可能需要/有权访问不同的表),但它提供了一种更好地组织数据和相关行为的方法。在这个 Zend 示例中,我们将使用映射器在域对象和网关对象之间来回移动数据;
如果以上是正确的,那么我仍然缺少这个:
域对象(a.k.a Business Objects) – 那些对象……我不明白……它们与其他对象的关系是什么?
关于这个网关/映射器架构,我们如何正确定义域对象?
【问题讨论】:
标签: php oop zend-framework business-objects