diff --git a/advanced_topics/object_oriented_programming.ipynb b/advanced_topics/object_oriented_programming.ipynb index 59974bc6c841755216aee1edb27bec52e95801d2..3edc786ead174a24360055e63a2c7e2e28a0c638 100644 --- a/advanced_topics/object_oriented_programming.ipynb +++ b/advanced_topics/object_oriented_programming.ipynb @@ -1052,10 +1052,10 @@ "The `NumberOperator` class has also overridden the `preprocess` method, to\n", "ensure that all values handled by the `Operator` are numbers. This method gets\n", "called within the `Operator.run` method - for a `NumberOperator` instance, the\n", - "`NumberOperator.preprocess` method will get called<sup>1</sup>.\n", + "`NumberOperator.preprocess` method will get called<sup>3</sup>.\n", "\n", "\n", - "> <sup>1</sup> When a sub-class overrides a base-class method, it is still\n", + "> <sup>3</sup> When a sub-class overrides a base-class method, it is still\n", "> possible to access the base-class implementation [via the `super()`\n", "> function](https://stackoverflow.com/a/4747427) (the preferred method), or by\n", "> [explicitly calling the base-class\n", @@ -1658,7 +1658,8 @@ "\n", "However, because a Python method can be written to accept any number or type\n", "of arguments, it is very easy to to build your own overloading logic by\n", - "writing a \"dispatch\" method. Here is YACE (Yet Another Contrived Example):" + "writing a \"dispatch\" method<sup>4</sup>. Here is YACE (Yet Another Contrived\n", + "Example):" ] }, { @@ -1697,6 +1698,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "> <sup>4</sup>Another option is the [`functools.singledispatch`\n", + "> decorator](https://docs.python.org/3.5/library/functools.html#functools.singledispatch),\n", + "> which is more complicated, but may allow you to write your dispatch logic in\n", + "> a more concise manner.\n", + "\n", + "\n", "<a class=\"anchor\" id=\"useful-references\"></a>\n", "## Useful references\n", "\n", diff --git a/advanced_topics/object_oriented_programming.md b/advanced_topics/object_oriented_programming.md index a180108b8a2f771d396b67b8d64a7c122607aa0a..68be0603739e08005ba38acfc30fd3fd47dcd540 100644 --- a/advanced_topics/object_oriented_programming.md +++ b/advanced_topics/object_oriented_programming.md @@ -853,10 +853,10 @@ Here we are registering all of the functionality that is provided by the The `NumberOperator` class has also overridden the `preprocess` method, to ensure that all values handled by the `Operator` are numbers. This method gets called within the `Operator.run` method - for a `NumberOperator` instance, the -`NumberOperator.preprocess` method will get called<sup>1</sup>. +`NumberOperator.preprocess` method will get called<sup>3</sup>. -> <sup>1</sup> When a sub-class overrides a base-class method, it is still +> <sup>3</sup> When a sub-class overrides a base-class method, it is still > possible to access the base-class implementation [via the `super()` > function](https://stackoverflow.com/a/4747427) (the preferred method), or by > [explicitly calling the base-class @@ -1361,7 +1361,8 @@ types) is used. However, because a Python method can be written to accept any number or type of arguments, it is very easy to to build your own overloading logic by -writing a "dispatch" method. Here is YACE (Yet Another Contrived Example): +writing a "dispatch" method<sup>4</sup>. Here is YACE (Yet Another Contrived +Example): ``` @@ -1391,6 +1392,11 @@ print('Add three: {}'.format(a.add(1, 2, 3))) print('Add four: {}'.format(a.add(1, 2, 3, 4))) ``` +> <sup>4</sup>Another option is the [`functools.singledispatch` +> decorator](https://docs.python.org/3.5/library/functools.html#functools.singledispatch), +> which is more complicated, but may allow you to write your dispatch logic in +> a more concise manner. + <a class="anchor" id="useful-references"></a> ## Useful references