I have a record class with 18 properties.
Before that class can be submitted to the database, all 18 properties must have validated data.
Because I’m OOP-ifying a working procedural webapp, I went about this sort of backwards.
First I addressed workflow for modifying existing records. At the time, it made sense to throw all 18 properties into the __construct method and avoid craploads of setters. A separate loader class handles the dbase business and can return either single objects or an array of record objects. That all worked ok.
But then it came time to address the new record creation workflow, and suddenly I needed to instantiate an empty record, except my record constructor is a hungry beast that wants 18 parameters…
…so you strip the constructor? But then I’d have to add 18 setters and call them all each time I want to work with an existing record…
doesn’t seem like much of an improvement! :-/
How do real programmers handle this? (I’m just a weenie hobbyist…)
Either default arguments is one option, but then you have to fill out a large number of null’s if you only want to use, say, the first and last.
Then again, you could do array looping:
Or, if you wanted to keep your old constructor signature:
The new version also gives you the option to simply: