diff --git a/lib/interface.js b/lib/interface.js index 762cb50..24d8d3c 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -36,6 +36,9 @@ exports.extend = function() } +exports.abstractMethod = util.createAbstractMethod; + + /** * Default interface implementation * @@ -71,10 +74,10 @@ function prop_check( props ) { for ( prop in props ) { - if ( !( props[ prop ] instanceof Function ) ) + if ( util.isAbstractMethod( props[ prop ] ) === false ) { throw new Error( - "Only methods are permitted within Interface definitons" + "Only abstract methods are permitted within Interface definitons" ); } } diff --git a/test/test-interface.js b/test/test-interface.js index 274f6a9..302af9a 100644 --- a/test/test-interface.js +++ b/test/test-interface.js @@ -26,7 +26,8 @@ require( './common' ); var assert = require( 'assert' ), Class = require( 'class' ), - Interface = require( 'interface' ); + Interface = require( 'interface' ), + abstractMethod = Interface.abstractMethod; var FooType = Interface.extend(); @@ -50,13 +51,26 @@ assert.throws( function() // properties (non-methods) are not permitted prop: 'not permitted', }); -}, Error, "Only methods are permitted within Interface definitions" ); +}, Error, "Properties are not permitted within Interface definitions" ); -assert.doesNotThrow( function() +assert.throws( function() { Interface.extend( { - method: function() {}, + // concrete method + method: function() {} }); -}, Error, "Method declarations are allowed within Interface definitions" ); +}, Error, "Concrete methods are not permitted within Interface definitions" ); + +assert.doesNotThrow( + function() + { + Interface.extend( + { + method: abstractMethod(), + }); + }, + Error, + "Abstract method declarations are allowed within Interface definitions" +);