I am using Propel, a PHP ORM.
I really like it. I love to be able to write this code:
$offer->setTitle('20% off everything')->save();
But what about if I want to create a increaseImpressions method?.
Would you use开发者_运维百科 it like this:
$offer->increaseImpressions()
or like this:
$offer->increaseImpressions()->save()
?
In other words, would you save the object inside or outside the increaseImpressions method? Can you also please tell me why?
I guess this is a question about OOP.
Thanks, Dan
I would suggest the the second example:
$offer->increaseImpressions()->save()
Essentially, the increaseImpressions method is just another setter. Calling save outside the increaseImpressions method keeps it consistent with the rest of the setter methods.
For something as important as logging impressions it might make sense to make the operation atomic and put the save inside the method. Do you work with any developers you respect whose advice you could ask?
精彩评论