Last active
November 24, 2018 01:02
-
-
Save jdrda/a9f0433af2291b2fea94af5871e48a8d to your computer and use it in GitHub Desktop.
General setter with possibility of set default value suitable for writing other setters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product | |
{ | |
/** | |
* Product name to be set | |
* | |
* @var string | |
*/ | |
private $_name; | |
/** | |
* General setter prototype | |
* | |
* @param $variable | |
* @param $value | |
* @param $defaultValue | |
* @return bool If true - value has been set, if false - default value used | |
*/ | |
private function _generalSetter($variable, $value, $defaultValue){ | |
if(empty($value) === false){ | |
$variable = $value; | |
return true; | |
} | |
else{ | |
$variable = $defaultValue; | |
return false; | |
} | |
} | |
/** | |
* Setter for product name | |
* | |
* This setter uses general setter above to be more simple | |
* | |
* @param $productName | |
* @return bool | |
*/ | |
public function setProductName($productName){ | |
return $this->_generalSetter($this->_name, $productName, 'Box of milk'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment