1
0
Fork 0

Removed Interface.abstractMethod() in favor of 'abstract' keyword

closure/master
Mike Gerwitz 2010-12-28 20:13:50 -05:00
parent 44186068b4
commit 928a0ea297
2 changed files with 23 additions and 39 deletions

View File

@ -36,9 +36,6 @@ exports.extend = function()
}
exports.abstractMethod = util.createAbstractMethod;
/**
* Default interface implementation
*
@ -50,13 +47,24 @@ function Interface() {}
function extend()
{
var args = Array.prototype.slice.call( arguments ),
props = prop_check( args.pop() ) || {},
props = args.pop() || {},
base = args.pop() || Interface,
prototype = new base();
var new_interface = function() {};
util.propCopy( props, prototype );
util.propCopy( props, prototype, {
each: function( name, value )
{
if ( util.isAbstractMethod( value ) === false )
{
throw TypeError(
"Only abstract methods are permitted within Interface " +
"definitons"
);
}
},
} );
attach_extend( new_interface );
new_interface.prototype = prototype;
@ -69,29 +77,6 @@ function extend()
}
/**
* Checks to ensure that only methods are being declared
*
* @param {Object} props interface definition
*
* @return {Object} the same properties that were passed to the function
*/
function prop_check( props )
{
for ( prop in props )
{
if ( util.isAbstractMethod( props[ prop ] ) === false )
{
throw new Error(
"Only abstract methods are permitted within Interface definitons"
);
}
}
return props;
}
/**
* Attaches extend method to the given function (interface)
*

View File

@ -24,8 +24,7 @@
var common = require( './common' ),
assert = require( 'assert' ),
Interface = common.require( 'interface' ),
abstractMethod = Interface.abstractMethod;
Interface = common.require( 'interface' );
assert.throws( function()
@ -35,7 +34,7 @@ assert.throws( function()
// properties (non-methods) are not permitted
prop: 'not permitted',
});
}, Error, "Properties are not permitted within Interface definitions" );
}, TypeError, "Properties are not permitted within Interface definitions" );
assert.throws( function()
{
@ -44,24 +43,24 @@ assert.throws( function()
// concrete method
method: function() {}
});
}, Error, "Concrete methods are not permitted within Interface definitions" );
}, TypeError, "Concrete methods are not permitted within Interface definitions" );
assert.doesNotThrow(
function()
{
Interface.extend(
{
method: abstractMethod(),
'abstract method': [],
});
},
Error,
TypeError,
"Abstract method declarations are allowed within Interface definitions"
);
var BaseType = Interface.extend(
{
method: abstractMethod(),
'abstract method': [],
});
assert.ok(
@ -72,7 +71,7 @@ assert.ok(
var SubType = Interface.extend( BaseType,
{
second: abstractMethod(),
'abstract second': [],
});
assert.ok(
@ -99,7 +98,7 @@ assert.ok(
var SubType2 = BaseType.extend(
{
second: abstractMethod(),
'abstract second': [],
});
assert.ok(