-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1-theory.js
More file actions
49 lines (40 loc) · 927 Bytes
/
1-theory.js
File metadata and controls
49 lines (40 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';
class AbstractClass {
constructor() {
const proto = Object.getPrototypeOf(this);
if (proto.constructor === AbstractClass) {
throw new Error('Abstract class should not be instanciated');
}
}
method1(value) {
const s = JSON.stringify({ method1: { value } });
throw new Error('Method is not implemented: ' + s);
}
method2() {
throw new Error('Method is not implemented');
}
}
class Implementation extends AbstractClass {
constructor(value) {
super();
this.field = value;
}
method1(value) {
this.field = value;
}
}
// Usage
try {
const ac = new AbstractClass();
ac.method1('value1');
} catch (error) {
console.log(`Error: ${error.message}`);
}
const instance = new Implementation('value2');
instance.method1('value3');
console.dir(instance);
try {
instance.method2('value4');
} catch (error) {
console.log(`Error: ${error.message}`);
}