4

What do you call a class that has methods that

  • take input (from user, from GET or POST)
  • transform it to a business object and return that object

example ...

class Input
{
    function getObject(array $input)
    {
        $o = new Object();
        $o->setVars($input);
        return $o;
    }
}

$o = (new Input())->getObject($_POST);
1

As @RobertHarvey commented a Factory Method might be an appropriate name. When it comes to web applications Model Binding is another good term I've seen in reference to mapping data in an HTTP request to some sort of concrete object.

Model binding in ASP.NET Core MVC maps data from HTTP requests to action method parameters. The parameters may be simple types such as strings, integers, or floats, or they may be complex types.

Source: Introduction to model binding

A Data Mapper is also a good name.

Whichever one you choose will largely depend on context. If we are talking about parameters in an HTTP request go with Model Binder. If talking about taking data from one type and converting it to another then a Data Mapper fits. Lastly if it is a general purpose method that decides at runtime which concrete type to create based on input then you have a Factory Method/Object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.