iwmlib/lib/interface.js

30 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-03-21 09:57:27 +01:00
// In order to test this interface implementation run jsc interface.js
export default class Interface {
// Abstract interface that should be extended in interface subclasses.
// By convention all interfaces should start with an upper 'I'
static implementationError(klass) {
let interfaceKeys = Reflect.ownKeys(this.prototype)
let classKeys = Reflect.ownKeys(klass.prototype)
2019-07-18 12:26:39 +02:00
for (let key of interfaceKeys) {
2019-03-21 09:57:27 +01:00
let interfaceDesc = this.prototype[key]
let classDesc = klass.prototype[key]
2019-07-18 12:26:39 +02:00
if (typeof classDesc == 'undefined') return 'Missing ' + key
2019-03-21 09:57:27 +01:00
}
return null
}
static implementedBy(klass) {
// In the first step only checks whether the methods of this
// interface are all implemented by the given class
let error = this.implementationError(klass)
return error == null
}
2019-07-18 12:26:39 +02:00
// TODO: Specify optional methods
// static optionalMethods() {
// return [this.onMouseWheel]
// }
2019-03-21 09:57:27 +01:00
}