这是域对象类吗?

发布于 2024-11-04 05:33:33 字数 2731 浏览 4 评论 0原文

如果域对象 = 业务对象,那么我期望看到像 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 示例中,我们将使用映射器在域对象和网关对象之间来回移动数据;

如果上述内容是正确的,那么我仍然缺少这个:

域对象(又名业务对象) - 这些对象......我不明白......它们与其他对象的关系是什么?

我们如何正确定义域对象 - 关于这个网关/映射器架构?

If Domain Object = Business Object, then I was expecting to see things like findTaxValues(); or searchBooksByAuthor(); methods, instead, I see generally getters and setters.

1)

Is this a Domain Object Class ?

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;
    }
}

Update:

2) Since it seems to be a Domain Object Class:

I'm having a hard time studying Zend Quick Start guide.

Here's my resume so far:

Table Data Gateway Objects – Those are object copies of our tables and they should contain table related generic queries. On Zend, we will use them to perform generic queries that will work across different database vendors via Zend_Db_Table_Abstract extension. What will those gateway objects do? They will connect (via an adapter) to our data source (ex: a MySQL database), on a generic (non-database-specific) way;

Data Mappers Objects - Those objects will work between our data source and our domain object models. They may, or may not, use the Gateway to have access to the data source. Their job is to, while referring NOT to a specific table BUT to a domain (that may need/have access to different tables), it provides a way to better organize the data and the related behaviour. On this Zend example, we will use the mapper to move data back and forward between Domain Objects and Gateway Objects;

If the above is correct, then I'm still missing this:

Domain Objects (a.k.a Business Objects) – Those objects … I don't get here... what is their relation with the others ?

How can we properly define Domain Object - regarding this Gateway / Mapper architecture ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人疚 2024-11-11 05:33:33

我相信您将业务经理或类似人员与域对象混淆了。域对象应该是一个业务实体,因此我将确认您的代码示例是一个域对象

编辑|回答您的更新:

域对象是在某些特定业务问题中扮演某些业务角色的实体。如果我没有理解错误的 Zend 定义,“数据映射器对象”可能是“域对象”,但并非在所有情况下都是如此。

I believe you're confusing business managers or something like that with domain objects. A domain object should be a business entity, so I'm going to confirm that your code sample is a domain object.

EDIT | Answering to your update:

A domain object is an entity playing some business role around in some specific business concern. If I don't understand wrong Zend's definitions, "Data Mapper Objects" could be "domain objects", but not in all cases.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文