Skip to content

Commit 39c59d3

Browse files
committed
🎨 Rearrange oop section
* Add graph for oop * Rename summary
1 parent aa57dd5 commit 39c59d3

File tree

3 files changed

+51
-15
lines changed

3 files changed

+51
-15
lines changed

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"pygments_pytest",
4444
"sphinx.ext.autodoc",
4545
"sphinx.ext.viewcode",
46+
"sphinx.ext.graphviz",
4647
"sphinx.ext.intersphinx",
4748
"sphinxcontrib.plantuml",
4849
"sphinxcontrib.cairosvgconverter",
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
Summary
2-
=======
1+
Coherent example
2+
================
33

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

78
#. First, we create a base class:
89

910
.. literalinclude:: form.py
1011
:language: python
1112
:linenos:
12-
:lines: 4-13
13-
:lineno-start: 4
13+
:lines: 1-12
14+
:lineno-start: 1
1415

1516
Line 7
1617
The ``__init__`` method requires one instance (``self``) and two
1718
parameters.
1819
Lines 8 and 9
1920
The two instance variables ``x`` and ``y``, which are accessed via
2021
``self``.
21-
Line 11
22+
Line 10
2223
The ``move`` method requires one instance (``self``) and two parameters.
23-
Lines 12 and 13
24+
Lines 11 and 12
2425
Instance variables that are set in the ``move`` method.
2526

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

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

4546
.. literalinclude:: form.py
4647
:language: python
4748
:linenos:
48-
:lines: 27-
49+
:lines: 27-43
4950
:lineno-start: 27
5051

51-
Lines 30 and 31
52+
Lines 29 and 30
5253
``pi`` and ``circles`` are class variables for ``Circle``.
53-
Line 33
54+
Line 34
5455
In the ``__init__`` method, the instance inserts itself into the
5556
``circles`` list.
56-
Lines 38 and 39
57+
Lines 37 and 38
5758
``circumferences`` is a class method and takes the class itself
5859
(``cls``) as a parameter.
59-
Line 42
60+
Line 41
6061
uses the parameter ``cls`` to access the class variable ``circles``.
6162

6263
Now you can create some instances of the class ``Circle`` and analyse them.

docs/oop/index.rst

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,40 @@ Python offers full support for `object-oriented programming
66
(object-oriented programming)`. The following listing is an example that could
77
be the beginning of a simple shapes module for a drawing program.
88

9+
10+
.. graphviz::
11+
:layout: neato
12+
13+
graph oop {
14+
graph [fontname = "Calibri", fontsize="16", overlap=false];
15+
node [fontname = "Calibri", fontsize="16", style="bold", penwidth="5px"];
16+
edge [fontname = "Calibri", fontsize="16", style="bold", penwidth="5px"];
17+
tooltip="Objektorientierte Programmierung";
18+
oop [
19+
label="Objektorientierte\nProgrammierung\n(OOP)",
20+
color="#FF66B3"]
21+
objects [
22+
label="Objekte",
23+
color="#BF80FF"]
24+
polymorphism [
25+
label="Polymorphismus",
26+
color="#9999FF"]
27+
classes [
28+
label="Klassen",
29+
color="#00FF80"]
30+
inheritance [
31+
label="Vererbung",
32+
color="#4da6ff"]
33+
encapsulation [
34+
label="Kapselung",
35+
color="#00FFFF"]
36+
oop -- objects [color="#FF66B3;0.5:#BF80FF"]
37+
oop -- polymorphism [color="#FF66B3;0.5:#9999FF"]
38+
oop -- classes [color="#FF66B3;0.5:#00FF80"]
39+
oop -- inheritance [color="#FF66B3;0.5:#4da6ff"]
40+
oop -- encapsulation [color="#FF66B3;0.5:#00FFFF"]
41+
}
42+
943
.. toctree::
1044
:titlesonly:
1145
:hidden:
@@ -14,7 +48,7 @@ be the beginning of a simple shapes module for a drawing program.
1448
variables
1549
methods
1650
inheritance
17-
summary
51+
coherent
1852
private
1953
property
2054
namespaces

0 commit comments

Comments
 (0)