Need Help With OOP Best Practices

Yes, you are right.
I think you are overcomplicating things to the point where they lose the sense.

For such an abstract question there is obviously no single answer. The only answer you can get - “it depends”.

  • in some cases you want a common method with a collection.
  • in some cases you want separate methods for separate properties
  • sometimes it is useful to have both. For example, Laravel’s ActiveRecord lets you set every model’s property either by a single assignment or using bulk storage:

E.g.,

$user = new User;
$user->name = 'John';
$user->description = 'programmer';

vs.

$user = new User('John', 'programmer');

(note that these codes do only assignment, but do not persist assigned properties in the database).

So the only particular answer you can get if as a particular question. Say, for the question from the OP, I never heard of separate methods to persist separate properties in database. So you better go for the option #1:

$personTable->save($person);
// or, using AR
$person->save();
// or, using optimized DM
$table->save($person);
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.