Last active
August 29, 2015 14:14
-
-
Save eltonea/96978ab6620d402f9fe6 to your computer and use it in GitHub Desktop.
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
function ICalculator(){}; | |
/* | |
Interface contract. | |
*/ | |
ICalculator.prototype.Sum = function(a, b){ | |
throw new Error('You have that implement this.'); | |
}; | |
ICalculator.prototype.Subtraction = function(a, b){ | |
throw new Error('You have that implement this.'); | |
}; | |
ICalculator.prototype.Division = function(a, b){ | |
throw new Error('You have that implement this.'); | |
}; | |
ICalculator.prototype.Multiplication = function(a, b){ | |
throw new Error('You have that implement this.'); | |
}; | |
/* | |
Methods to implementation. | |
*/ | |
function Calculator(){}; | |
Calculator.prototype = ICalculator.prototype; //Implementation of methods. | |
Calculator.prototype.Sum = function(a, b){ | |
var value = a + b; | |
if (isNaN(value)) | |
return 'Not was possible'; | |
return value; | |
}; | |
Calculator.prototype.Subtraction = function(a, b){ | |
var value = a - b; | |
if (isNaN(value)) | |
throw new Error('Not was possible'); | |
return value; | |
}; | |
Calculator.prototype.Division = function(a, b){ | |
var value = a / b; | |
if (isNaN(value)) | |
throw new Error('Not was possible'); | |
return value; | |
}; | |
Calculator.prototype.Multiplication = function(a, b){ | |
var value = a * b; | |
if (isNaN(value)) | |
throw new Error('Not was possible'); | |
return value; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I would like to know, if you implement your interface as this sample.
Thanks.