You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/classes.md
+29Lines changed: 29 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -120,8 +120,37 @@ As always these modifiers work for both member properties and member functions.
120
120
`abstract` can be thought of as an access modifier. We present it separately because opposed to the previously mentioned modifiers it can be on a `class` as well as any member of the class. Having an `abstract` modifier primarily means that such functionality *cannot be directly invoked* and a child class must provide the functionality.
121
121
122
122
*`abstract`**classes** cannot be directly instantiated. Instead the user must create some `class` that inherits from the `abstract class`.
123
+
124
+
```ts
125
+
abstractclassFooCommand {}
126
+
127
+
classBarCommandextendsFooCommand {}
128
+
129
+
const fooCommand:FooCommand=newFooCommand(); // Cannot create an instance of an abstract class.
130
+
131
+
const barCommand =newBarCommand(); // You can create an instance of a class that inherits from an abstract class.
132
+
```
133
+
123
134
*`abstract`**members** cannot be directly accessed and a child class must provide the functionality.
124
135
136
+
```ts
137
+
abstractclassFooCommand {
138
+
abstract execute():string;
139
+
}
140
+
141
+
classBarErrorCommandextendsFooCommand {} // 'BarErrorCommand' needs implement abstract member 'execute'.
142
+
143
+
classBarCommandextendsFooCommand {
144
+
execute() {
145
+
return`Command Bar executed`;
146
+
}
147
+
}
148
+
149
+
const barCommand =newBarCommand();
150
+
151
+
barCommand.execute(); // Command Bar executed
152
+
```
153
+
125
154
### Constructor is optional
126
155
127
156
The class does not need to have a constructor. e.g. the following is perfectly fine.
0 commit comments