mardi 3 mai 2016

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

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.

Aucun commentaire:

Enregistrer un commentaire