vendredi 29 juin 2018

PHP model with too many constructor arguments

In my current project I am implementing an Model-View-Presenter pattern. Most of my classes that represent domain objects have too many constructor arguments. Take this for example (NOTE: This is just a made-up class, just assume that models need too many arguments):

class Person {
    private $id;
    private $first_name;
    private $middle_name;
    private $last_name;
    private $birthdate;

    private $schoolName;
    private $schoolYearLevel;

    ... more properties

    public function __constructor($id, $first_name, $middle_name, $last_name, .. etc){
        ... some code to set the properties
    }
}

Suppose this class has many independent values needed for construction (7+ values), what good design can I use? The values are fetched rows from a database.

Aucun commentaire:

Enregistrer un commentaire