0

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.

Dennis
  • 7,907
  • 11
  • 65
  • 115
  • Sounds like a pretty simple request/response; not really any specific "design pattern" – Mark Baker May 03 '16 at 15:19
  • Thanks. Well, what if I move the data compilation code into the `createObject` method itself, will that make a difference? For example, there may be some mild logic if/then/else branching, and data assembly from various sources (GET, POST, DB, Cookies, SESSION, etc). Will that change the nature of the "Pattern"? – Dennis May 03 '16 at 15:44
  • you might look at datamappers – jeremy Aug 01 '16 at 00:51

0 Answers0