Use a multiple functions or just one with more arguments?
Posted: Sat Aug 06, 2011 9:41 am
In my minimal amount of PHP development experience, this is a question I've asked myself numerous times. Is it "better" to use multiple functions to perform a task or simply use a single function but with more arguments?
Take this most recent scenario as an example. I'm developing an application that will be for people that sell on Amazon. One of the purposes of this application is to calculate total expenses a seller may incur if listing a particular item on Amazon such as Amazon fees, shipping supplies, etc. Would it be better to do something like this:
or this:
Take this most recent scenario as an example. I'm developing an application that will be for people that sell on Amazon. One of the purposes of this application is to calculate total expenses a seller may incur if listing a particular item on Amazon such as Amazon fees, shipping supplies, etc. Would it be better to do something like this:
Code: Select all
public function getAmazonExpense($category,$type) {
switch ($category) {
case 'media':
return 'something';
break;
case 'gardening':
return 'something';
break;
default:
return 'something else';
}Code: Select all
public function getAmazonMediaExpense($type) {
return 'something';
}
public function getAmazonGardeningExpense($type) {
return 'something';
}