What is a name for a pattern where it receives data or asks for data and returns back an object?

对着背影说爱祢 提交于 2019-12-12 06:26:56

问题


Question 1

Is there a name for the pattern below?

class Pattern
{
    function createObject(array $data)
    {
        $object = new Object();
        $object->setPropertyA($data['A']);
        $object->setPropertyB($data['B']);
        $object->setPropertyC($data['C']);

        return $object;
    }
}

Question 2

Is there a name for the above pattern if it is altered to where $data is acquired inside the method? Specifically code below:

class Pattern2
{
    function createObject()
    {
        $data = $this->service->acquireData();

        $object = new Object();
        $object->setPropertyA($data['A']);
        $object->setPropertyB($data['B']);
        $object->setPropertyC($data['C']);

        return $object;
    }
}

What's the purpose?

My purpose is to seek out a pattern that acquires data from somewhere and returns a ready-to-use single object. To differentiate from the factory method, my purpose is not to decide at run time which polymorphic object to create, but to return a ready to use, populated with data, known single object. I want to know what it is called to help me do better research on the pattern and similar patterns and on how they are used.

来源:https://stackoverflow.com/questions/37007976/what-is-a-name-for-a-pattern-where-it-receives-data-or-asks-for-data-and-returns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!