@@ -129,8 +129,21 @@ class DataArray:
129
129
...
130
130
```
131
131
132
+ . . .
133
+
134
+ ` DataArray ` * has a* ` geometry ` (e.g. ` Grid ` ) and an ` item ` (` ItemInfo ` ).
135
+
132
136
## Inheritance
133
137
138
+ ::: {.incremental}
139
+
140
+ * Inheritance is a way to reuse code and specialize behavior.
141
+ * A child class inherits the attributes and methods from the parent class.
142
+ * A child class can override the methods of the parent class.
143
+ * A child class can add new methods.
144
+
145
+ :::
146
+
134
147
## Inheritance - Example
135
148
136
149
``` {mermaid}
@@ -166,6 +179,11 @@ class GeometryFMVerticalProfile{
166
179
_GeometryFMLayered <|-- GeometryFMVerticalProfile
167
180
```
168
181
182
+ . . .
183
+
184
+ ` GeometryFM3D ` inherits from ` _GeometryFMLayered ` , it * is a* ` _GeometryFMLayered ` .
185
+
186
+
169
187
## Inheritance - Example (2)
170
188
171
189
``` python
@@ -180,6 +198,7 @@ class _GeometryFMLayered(_GeometryFM):
180
198
self ._n_sigma = n_sigma
181
199
```
182
200
201
+
183
202
## Composition vs inheritance
184
203
185
204
::: {.incremental}
@@ -226,14 +245,13 @@ def repeated_string(s, n):
226
245
227
246
::: {.incremental}
228
247
* Python is a dynamically typed language
229
- * Types are not checked at compile time
230
- * Types are checked at runtime
248
+ * Types are not checked at compile time by the interpreter
249
+ * Types * can* be checked before runtime using a linter (e.g. ` mypy ` )
250
+ * Type hints can be used by VS Code to provide auto-completion
231
251
:::
232
252
233
253
. . .
234
254
235
- ** Python** with type hints
236
-
237
255
``` python
238
256
n: int = 2
239
257
s: str = " Hello"
@@ -379,6 +397,9 @@ Dundermethods:
379
397
380
398
``` python
381
399
class JavaLikeToolbox :
400
+
401
+ def __init__ (self , tools : Collection[Tool]):
402
+ self .tools = tools
382
403
383
404
def getToolByName (self , name : str ) -> Tool:
384
405
for tool in self .tools:
@@ -401,6 +422,9 @@ Hammer()
401
422
``` python
402
423
class Toolbox :
403
424
425
+ def __init__ (self , tools : Collection[Tool]):
426
+ self ._tools = {tool.name: tool for tool in tools}
427
+
404
428
def __getitem__ (self , name : str ) -> Tool:
405
429
return self ._tools[name]
406
430
0 commit comments