Skip to content

Commit

Permalink
🎨 Rearrange oop section
Browse files Browse the repository at this point in the history
* Add graph for oop
* Rename summary
  • Loading branch information
veit committed Dec 29, 2024
1 parent aa57dd5 commit 39c59d3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"pygments_pytest",
"sphinx.ext.autodoc",
"sphinx.ext.viewcode",
"sphinx.ext.graphviz",
"sphinx.ext.intersphinx",
"sphinxcontrib.plantuml",
"sphinxcontrib.cairosvgconverter",
Expand Down
29 changes: 15 additions & 14 deletions docs/oop/summary.rst → docs/oop/coherent.rst
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
Summary
=======
Coherent example
================

The points made so far, are the basics of using classes and objects in Python. I
will now summarise these basics in a single example:
The points mentioned so far are the basics of using classes and objects in
Python. I will now illustrate these basics in a coherent example:
:download:`form.py`.

#. First, we create a base class:

.. literalinclude:: form.py
:language: python
:linenos:
:lines: 4-13
:lineno-start: 4
:lines: 1-12
:lineno-start: 1

Line 7
The ``__init__`` method requires one instance (``self``) and two
parameters.
Lines 8 and 9
The two instance variables ``x`` and ``y``, which are accessed via
``self``.
Line 11
Line 10
The ``move`` method requires one instance (``self``) and two parameters.
Lines 12 and 13
Lines 11 and 12
Instance variables that are set in the ``move`` method.

#. Next, create a subclass that inherits from the base class ``Form``:
Expand All @@ -37,26 +38,26 @@ will now summarise these basics in a single example:
``Square``’s ``__init__`` takes one instance (``self``) and three
parameters, all with defaults.
Line 20
``Circle``’s ``__init__`` uses ``super()`` to call ``Form``’s
``Square``’s ``__init__`` uses ``super()`` to call ``Form``’s
``__init__``.

#. Finally, we create another subclass that also contains a static method:

.. literalinclude:: form.py
:language: python
:linenos:
:lines: 27-
:lines: 27-43
:lineno-start: 27

Lines 30 and 31
Lines 29 and 30
``pi`` and ``circles`` are class variables for ``Circle``.
Line 33
Line 34
In the ``__init__`` method, the instance inserts itself into the
``circles`` list.
Lines 38 and 39
Lines 37 and 38
``circumferences`` is a class method and takes the class itself
(``cls``) as a parameter.
Line 42
Line 41
uses the parameter ``cls`` to access the class variable ``circles``.

Now you can create some instances of the class ``Circle`` and analyse them.
Expand Down
36 changes: 35 additions & 1 deletion docs/oop/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ Python offers full support for `object-oriented programming
(object-oriented programming)`. The following listing is an example that could
be the beginning of a simple shapes module for a drawing program.


.. graphviz::
:layout: neato

graph oop {
graph [fontname = "Calibri", fontsize="16", overlap=false];
node [fontname = "Calibri", fontsize="16", style="bold", penwidth="5px"];
edge [fontname = "Calibri", fontsize="16", style="bold", penwidth="5px"];
tooltip="Objektorientierte Programmierung";
oop [
label="Objektorientierte\nProgrammierung\n(OOP)",
color="#FF66B3"]
objects [
label="Objekte",
color="#BF80FF"]
polymorphism [
label="Polymorphismus",
color="#9999FF"]
classes [
label="Klassen",
color="#00FF80"]
inheritance [
label="Vererbung",
color="#4da6ff"]
encapsulation [
label="Kapselung",
color="#00FFFF"]
oop -- objects [color="#FF66B3;0.5:#BF80FF"]
oop -- polymorphism [color="#FF66B3;0.5:#9999FF"]
oop -- classes [color="#FF66B3;0.5:#00FF80"]
oop -- inheritance [color="#FF66B3;0.5:#4da6ff"]
oop -- encapsulation [color="#FF66B3;0.5:#00FFFF"]
}

.. toctree::
:titlesonly:
:hidden:
Expand All @@ -14,7 +48,7 @@ be the beginning of a simple shapes module for a drawing program.
variables
methods
inheritance
summary
coherent
private
property
namespaces
Expand Down

0 comments on commit 39c59d3

Please sign in to comment.