/** * A ConcreteClass. */ class NonNegativeSubtraction extends BinaryOperation { private $_a; private $_b; public function __construct($a = 0, $b = 0) { $this->_a = $a; $this->_b = $b; } protected function _getFirstNumber() { return $this->_a; } protected function _getSecondNumber() { return min($this->_a, $this->_b); } protected function _operator($a, $b) { return $a - $b; } } $sum = new Sum(84, 56); //140 echo $sum->getOperationResult(), "\n"; $nonNegativeSubtraction = new NonNegativeSubtraction(9, 14); //0 echo $nonNegativeSubtraction->getOperationResult();