Skip to content

Instantly share code, notes, and snippets.

@eltonea
Last active August 29, 2015 14:14
Show Gist options
  • Save eltonea/96978ab6620d402f9fe6 to your computer and use it in GitHub Desktop.
Save eltonea/96978ab6620d402f9fe6 to your computer and use it in GitHub Desktop.
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;
};
@eltonea
Copy link
Author

eltonea commented Feb 3, 2015

Hello,
I would like to know, if you implement your interface as this sample.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment