mardi 11 août 2015

Which pattern is this? (Factory/Builder/Mapper/other)

I took clues from DataMapper pattern to create something like this:

class Pattern
{
    public function patternFunction()
    {
        //Acquire Data
        $number = filter_input(INPUT_POST, "number", FILTER_SANITIZE_INT);

        //create and populate object
        $object = new Object();
        $object->setNumber($number);
        return $object;
    }
}

//usage:
$objectInstance = (new Pattern())->patternFunction();

But to me it also looks like a Factory pattern or a Builder pattern.

Which is it? and did I code it up correctly?

Purpose is to create an object instance populated with data.

Aucun commentaire:

Enregistrer un commentaire