diff options
| -rw-r--r-- | Info/10/2/Datenkapselung/slides-bank-wdh.md | 171 | ||||
| -rw-r--r-- | Info/10/2/Polymorphismus/handout.tex | 84 | ||||
| -rw-r--r-- | Info/10/2/Polymorphismus/slides-bank-account.md | 229 | ||||
| -rw-r--r-- | Info/10/2/Polymorphismus/slides.md | 511 | ||||
| -rw-r--r-- | Info/23_24/05/06/10B/abfrage.md | 28 | ||||
| l--------- | Info/23_24/05/06/10B/img/caterpillar_movement.png | 1 | ||||
| -rw-r--r-- | Info/23_24/05/06/10B/schedule.md | 32 | ||||
| -rw-r--r-- | Info/23_24/05/06/10B/slides.md | 23 | ||||
| l--------- | Info/23_24/05/06/10B/topic | 1 |
9 files changed, 630 insertions, 450 deletions
diff --git a/Info/10/2/Datenkapselung/slides-bank-wdh.md b/Info/10/2/Datenkapselung/slides-bank-wdh.md new file mode 100644 index 00000000..4bb6e059 --- /dev/null +++ b/Info/10/2/Datenkapselung/slides-bank-wdh.md @@ -0,0 +1,171 @@ +--- +author: Florian Fischer +aspectratio: 169 +header-includes: | + \usepackage{pifont} +--- + +## Lessons learned? AUFGABE 0 +<!-- \pgfdeclareradialshading[droplet color]{droplet}{\pgfqpoint{-10bp}{-10bp}}{color(0bp)=(droplet color!50!white); color(9bp)=(droplet color!75!white); color(18bp)=(droplet color!85!black); color(25bp)=(droplet color); color(50bp)=(droplet color!50!white)} --> +<!-- \colorlet{droplet color}{blue!50!cyan} --> + +**ZEIT: 5Min** + +Öffne das Bank Projekt in der Online-IDE. +Mach Dich insbesondere mit den Attributen der Klasse `Bank` sowie `Konto` vertraut. +Welche Probleme entstehen durch die fehlenden Zugriffsmodifikatoren? + +## Lessons learned? + +::: columns +:::: {.column} + +:::: +:::: column + +:::: +::: + +## Erkenntnis + +Auch in Software müssen, wie in der Realität, Zugriff fest geregelt sein. + +\vspace{1cm} +\pause + +### Dazu bieten Java die Zugrifsmodifikatoren +* `private`{.java} - Nur Zugriff innerhalb der selben Klasse +* `public`{.java} - Uneingeschränkter Zugriff + +\pause + +\begin{tikzpicture}[overlay, remember picture] + \node[rotate=-20,scale=3] at (12, 3) {\Huge \color{red} \textbf{!}}; +\end{tikzpicture} + +## Lessons learned? AUFGABE 1 + +**ZEIT: 3Min** + +Ergänze die Attribute der Klasse `Bank` und `Konto` um den Zugriffsmodifikator `private`{.java}. + +### Tipp: Syntax Deklaration von Attributden +`<Zugriffsmodifikator> <Datentype> <Attributname>;` + +## Grundsatz der Datenkapselung + +Zwei Aspekte sind wichtig: + +\vspace{0.5cm} + +> 1. **Nur** Objekt selbst sollte Zugriff auf seine Daten haben +> 2. **Benötigter** Zugriff von außen soll über von dem Objekt bereitgestellte Methoden erfolgen + +\begin{tikzpicture}[overlay, remember picture] + \only<3> { + \node[rotate=-30,scale=3] at (12, 3) {\Huge \color{red} \textbf{!}}; + } +\end{tikzpicture} + +## Datenkapselung Anwendung {.t} + +```{.java .linenos} +class Bankkonto { + public double kontostand; + private kontonummer; + + public gibBetrag() { return kontostand; } + private gibKontoNummer() { return kontonummer; } +} +``` + +## Datenkapselung Anwendung {.t} + +```{.java .linenos highlightlines=\{2\}} +class Bankkonto { + public double kontostand; + private kontonummer; + + public gibBetrag() { return kontostand; } + private gibKontoNummer() { return kontonummer; } +} +``` + +## Datenkapselung Anwendung {.t} + +```{.java .linenos highlightlines=\{2\}} +class Bankkonto { + public double kontostand; + private kontonummer; + + public gibBetrag() { return kontostand; } + private gibKontoNummer() { return kontonummer; } +} +``` + +\vspace{1cm} + +* Zeile 2: Uneingeschränkter Zugriff + +## Datenkapselung Anwendung {.t} + +```{.java .linenos highlightlines=\{2,6\}} +class Bankkonto { + public double kontostand; + private kontonummer; + + public gibBetrag() { return kontostand; } + private gibKontoNummer() { return kontonummer; } +} +``` + +\vspace{1cm} + +* Zeile 2: Uneingeschränkter Zugriff + +## Datenkapselung Anwendung {.t} + +```{.java .linenos highlightlines=\{2,6\}} +class Bankkonto { + public double kontostand; + private kontonummer; + + public gibBetrag() { return kontostand; } + private gibKontoNummer() { return kontonummer; } +} +``` + +\vspace{1cm} + +* Zeile 2: Uneingeschränkter Zugriff +* Zeile 6: Kein Zugriff von außen möglich + +## Lessons learned! + +::: columns +:::: {.column} + +:::: +:::: column + +:::: +::: + +<!-- \begin{tikzpicture}[ --> + <!-- overlay, --> + <!-- remember picture, --> + <!-- raindrop/.pic={ --> + <!-- code={\tikzset{scale=1/10} --> + <!-- \shade [shading=droplet] --> + <!-- (0,0) .. controls ++(0,-1) and ++(0,1) .. (1,-2) --> + <!-- arc (360:180:1) --> + <!-- .. controls ++(0,1) and ++(0,-1) .. (0,0) -- cycle; --> + <!-- } --> +<!-- }] --> + <!-- \only<2-> { --> + <!-- \path (3.65,3) pic {raindrop}; --> + <!-- \path (3.85,2.8) pic {raindrop}; --> + <!-- } --> + + <!-- \draw[transform canvas={shift={(8,1)}}, scale=2, line width=2pt] (3ex,2.5ex) -- (1.5ex,3ex) -- (0ex,2.5ex) to [out=-90, in=165] (1.5ex,0ex) to [out=15, in=-90] cycle (1.5ex,1.5ex) node {\Large \ding{51}}; --> +<!-- \end{tikzpicture} --> diff --git a/Info/10/2/Polymorphismus/handout.tex b/Info/10/2/Polymorphismus/handout.tex index b3b9bc70..a52240dc 100644 --- a/Info/10/2/Polymorphismus/handout.tex +++ b/Info/10/2/Polymorphismus/handout.tex @@ -1,58 +1,98 @@ \documentclass{handout} +\csname endofdump\endcsname +\usepackage{minted} +\usepackage{wrapfig} -\setlength\parindent{0pt} +\setlength\parindent{10pt} + +\title{Polymorphismus} \begin{document} -\textbf{AUFGABE 0:} Mache dich kurz mit dem Projekt Tierheim in der Online-IDE vertraut. \\ -Wie wird das Konzept der Vererbung im Code realisiert? \\[5mm] +\begin{multicols}{2} +\textbf{AUFGABE 0:} +\begin{itemize} +\item Kopiere das Projekt Tierheim und mache dich kurz damit vertraut. +\item Erkläre wie das Konzept der Vererbung im Code realisiert wird? +\item Markiere die in der Klasse \texttt{Katze} verwendeten Schlüsselwörter der Vererbung? +\item Gib an welche Objekte beim Ausführen der \texttt{main}-Methode der Klasse \texttt{Tierheim} erzeugt werden? Führe die Methode aus. +\end{itemize} -Wie wird der Konstruktor der Klasse Katze implementiert? \\[5mm] +\columnbreak -Welche Objekte sind bereits vorhanden? Führe das Programm aus. \\[5mm] +\begin{minted}{java} +class Katze extends Tier { + public Katze(String neuerName, + String neuesGeschlecht) + { + super(neuerName, neuesGeschlecht); + } + + public void lautAusgeben() { + System.out.println("Miau!Miau!"); + } +} +\end{minted} +\end{multicols} -\textbf{AUFGABE 1:} Überlege dir wie du unterschiedliche Tiere im Tierheim speicherst und setze deine Überlegung um. \\ -Welches Referenzattribut benötigt die Klasse Tierheim? \\[5mm] +\noindent\textbf{AUFGABE 1:} -\textbf{AUFGABE 2:} Begründe warum Pluto (Objekt der Klasse Hund) nicht ins Tierheim aufgenommen werden kann. \\[5mm] +Überlege dir wie du unterschiedliche Tiere im Tierheim speicherst und setze deine Überlegung um. -\begin{multicols}{2} +Welches Referenzattribut benötigt die Klasse \texttt{Tierheim}? \\[2mm] + +\noindent\textbf{AUFGABE 2:} + +Begründe warum Pluto (Objekt der Klasse \texttt{Hund}) nicht ins Tierheim aufgenommen werden kann. + +\begin{defbox}{Polymorphismus} +% \begin{tabularx}{\textwidth}{p{0.35\textwidth} p{0.03\textwidth} p{0.6\textwidth}} +% \vspace{0.1mm} +\begin{wrapfigure}{4}{0.55\textwidth} \begin{tikzpicture}[scale=0.45] - \begin{object}[text width=3.5cm]{th1}{0,0.5} + \begin{object}[text width=3.5cm]{th1}{0,3.5} \instanceOf{Tierheim} \attribute{tiere[0]} \attribute{tiere[1]} \attribute{...} \end{object} - \begin{object}[text width=4cm]{h1}{12,0} + \begin{object}[text width=4cm]{t1}{12,0} \instanceOf{Tier} \attribute{name="Wolle"} \attribute{geschlecht="ungewiss"} \end{object} - \begin{object}[text width=4cm]{t1}{12,5} + \begin{object}[text width=4cm]{h1}{12,6.5} \instanceOf{Hund} \attribute{name="Pluto" } \attribute{geschlecht="maennlich"} \attribute{rasse="comic"} \end{object} - \node[fill=black, circle, minimum size=0.05cm] (circle) at (2.2, -1.4) {}; - \draw[line width=2pt, -latex, draw=blue!80] (circle) edge [bend left=30] (8, 4.5) {}; - \node[fill=black, circle, minimum size=0.05cm] (circle2) at (2.2, -2.35) {}; + \node[fill=black, circle, minimum size=0.05cm] (circle) at (2.7, 1.6) {}; + \draw[line width=2pt, -latex, draw=blue!80] (circle) edge [bend left=30] (8, 6) {}; + \node[fill=black, circle, minimum size=0.05cm] (circle2) at (2.7, 0.55) {}; \draw[line width=2pt, -latex, draw=red!80] (circle2) edge [bend right=15] (8, -0.5) {}; -\end{tikzpicture} +\end{tikzpicture}% \\ +% \end{tabularx} +\end{wrapfigure} -\columnbreak +... ist die Eigenschaft, dass ein \textbf{Referenzattribut} nicht nur Objekte der als Datentyp angegebenen Klasse referenzieren kann, sondern auch Objekte \textbf{aller} zu dieser Klasse existierenden \textbf{Unterklassen}.% & & +\vspace{3mm} -Polymorphismus \textit{ist die Eigenschaft, dass ein \textbf{Referenzattribut} nicht nur Objekte der als Datentyp angegebenen Klasse referenzieren kann, sondern auch Objekte \textbf{aller} zu dieser Klasse existierenden \textbf{Unterklassen}.} +Wird ein Objekt einer \textbf{Unterklasse} über dieses Referenzattribut referenziert, so werden Attribute und Methoden verwendet, wie sie in \textbf{dessen Klasse} bekannt sind (und nicht die überschriebenen Methoden der Oberklasse). +\end{defbox} -\textit{Wird ein Objekt einer \textbf{Unterklasse} über dieses Referenzattribut referenziert, so werden Attribute und Methoden verwendet, wie sie in \textbf{seiner Klasse} bekannt sind (und nicht die überschriebenen Methoden der Oberklasse).} -\end{multicols} +\noindent\textbf{AUFGABE 3:} +Vervollständige die Klasse \texttt{Hund} als Spezialisierung der Klasse \texttt{Tier}.\\[2mm] -\textbf{AUFGABE 3:} Vervollständige die Klasse Hund als Spezialisierung der Klasse Tier. +\noindent\textbf{AUFGABE 4:} -\textbf{AUFGABE 4:} Implementiere die Methode \texttt{Tierheim.besuchen()} und überlege dir welche Ausgaben das Programm machen wird. Überprüfe deine Vermutung in dem du das Programm ausführst. +\begin{itemize} +\item Implementiere die Methode \mintinline{java}{Tierheim.besuchen()}. +\item Überlege dir welche Ausgaben das Programm machen wird. +\item Überprüfe deine Vermutung in dem du das Programm ausführst. +\end{itemize} \end{document} diff --git a/Info/10/2/Polymorphismus/slides-bank-account.md b/Info/10/2/Polymorphismus/slides-bank-account.md new file mode 100644 index 00000000..e8c3eaca --- /dev/null +++ b/Info/10/2/Polymorphismus/slides-bank-account.md @@ -0,0 +1,229 @@ +--- +author: Florian Fischer +aspectratio: 169 +--- + +## Vererbung - Problem + +\begin{tikzpicture} + \begin{class}[text width=4cm]{Sparkonto}{0,0} + \attribute{kontostand} + \attribute{kontonummer} + \attribute{zinssatz} + \operation{Einzahlen(betrag)} + \operation{Abheben(betrag)} + \operation{KontostandGeben()} + \operation{Verzinsen()} + \end{class} + + \begin{class}[text width=4cm]{Girokonto}{5,0} + \attribute{kontostand} + \attribute{kontonummer} + \operation{Einzahlen(betrag)} + \operation{Abheben(betrag)} + \operation{KontostandGeben()} + \end{class} + + \begin{class}[text width=4cm]{Firmenkonto}{10,0} + \attribute{kontostand} + \attribute{kontonummer} + \attribute{dispokredit} + \operation{Einzahlen(betrag)} + \operation{Abheben(betrag)} + \operation{KontostandGeben()} + \operation{DispokreditSetzen(wert)} + \end{class} +\end{tikzpicture} + +\pause + +Mögliche Probleme dieser Modellierung? + +## Vererbung - Generalisierung + +\resizebox{!}{0.5\textheight}{ +\begin{tikzpicture} + \begin{class}[text width=4cm]{Sparkonto}{0,0} + \attribute{kontostand} + \attribute{kontonummer} + \attribute{zinssatz} + \operation{Einzahlen(betrag)} + \operation{Abheben(betrag)} + \operation{KontostandGeben()} + \operation{Verzinsen()} + \end{class} + + \begin{class}[text width=4cm]{Girokonto}{5,0} + \attribute{kontostand} + \attribute{kontonummer} + \operation{Einzahlen(betrag)} + \operation{Abheben(betrag)} + \operation{KontostandGeben()} + \end{class} + + \begin{class}[text width=4cm]{Firmenkonto}{10,0} + \attribute{kontostand} + \attribute{kontonummer} + \attribute{dispokredit} + \operation{Einzahlen(betrag)} + \operation{Abheben(betrag)} + \operation{KontostandGeben()} + \operation{DispokreditSetzen(wert)} + \end{class} +\end{tikzpicture} +} + +**Idee**: Auslagern der gemeinsamen Attribute und Methoden in eine Oberklasse + +**Arbeitsauftrag 3min**: Zeichne ein Klassendiagramm mit einer gemeinsamen Oberklasse + +## Generalisierung - KONTO + +\begin{tikzpicture} + \node[rotate=30,scale=3] at (0, 3) {\Huge \color{red} \textbf{!}}; + + \begin{class}[text width=4cm]{KONTO}{5,4} + \attribute{kontostand} + \attribute{kontonummer} + \operation{Einzahlen(betrag)} + \operation{Abheben(betrag)} + \operation{KontostandGeben()} + \end{class} + + \begin{class}[text width=4cm]{SPARKONTO}{0,0} + \inherit{KONTO} + \attribute{zinssatz} + \operation{Verzinsen()} + \end{class} + + + \begin{class}[text width=4cm]{GIROKONTO}{5,0} + \inherit{KONTO} + \end{class} + + \begin{class}[text width=4cm]{FIRMENKONTO}{10,0} + \inherit{KONTO} + \attribute{dispokredit} + \operation{DispokreditSetzen(wert)} + \end{class} +\end{tikzpicture} + +## Generalisierung - Java + +\small + +::: columns +:::: {.column width=50%} +```java +class Konto { + private int kontostand; + private int kontonummer; + + public void Konto(int kNr) { + kontostand = 0; + kontonummer = kNr; + } + + public void Einzahlen(int betrag) { + ... +} +``` +:::: + +:::: {.column width=50%} +```java +// Klassendefinition ? + private double zinssatz; + + public void Sparkonto(int kNr, + double zs) { + // KONTO Initialisierung? + zinssatz = zs; + } + + public void Verzinsen() { + ... +} +``` +:::: +::: + +## Generalisierung - Java + +\small + +::: columns +:::: {.column width=50%} +```java +class Konto { + private int kontostand; + private int kontonummer; + + public void Konto(int kNr) { + kontostand = 0; + kontonummer = kNr; + } + + public void Einzahlen(int betrag) { + ... +} +``` +:::: + +:::: {.column width=50%} +```{.java highlightlines=\{1\}} +class Sparkonto extends Konto { + private double zinssatz; + + public void Sparkonto(int kNr, + double zs) { + super(kNr); + zinssatz = zs; + } + + public void Verzinsen() { + ... +} +``` +:::: +::: + +## Generalisierung - Java + +\small + +::: columns +:::: {.column width=50%} +```java +class Konto { + private int kontostand; + private int kontonummer; + + public void Konto(int kNr) { + kontostand = 0; + kontonummer = kNr; + } + + public void Einzahlen(int betrag) { + ... +} +``` +:::: + +:::: {.column width=50%} +```{.java highlightlines=\{1,6\}} +class Sparkonto extends KONTO { + private double zinssatz; + + public void Sparkonto(int kNr, + double zs) { + super(kNr); + zinssatz = zs; + } + + public void Verzinsen() { + ... +} +``` +:::: +::: diff --git a/Info/10/2/Polymorphismus/slides.md b/Info/10/2/Polymorphismus/slides.md index 24932baa..75530b69 100644 --- a/Info/10/2/Polymorphismus/slides.md +++ b/Info/10/2/Polymorphismus/slides.md @@ -1,182 +1,15 @@ --- author: Florian Fischer -theme: Rochester aspectratio: 169 -header-includes: | - \usepackage{pifont} --- - <!-- \pgfdeclareradialshading[droplet color]{droplet}{\pgfqpoint{-10bp}{-10bp}}{color(0bp)=(droplet color!50!white); color(9bp)=(droplet color!75!white); color(18bp)=(droplet color!85!black); color(25bp)=(droplet color); color(50bp)=(droplet color!50!white)} --> - <!-- \colorlet{droplet color}{blue!50!cyan} --> +## Wir bauen ein Auto -## Lessons learned? AUFGABE 0 +`\begin{center}`{=latex} +{height=85%} +`\end{center}`{=latex} -**ZEIT: 5Min** - -Öffne das Bank Projekt in der Online-IDE. -Mach Dich insbesondere mit den Attributen der Klasse `Bank` sowie `Konto` vertraut. -Welche Probleme entstehen durch die fehlenden Zugriffsmodifikatoren? - -## Lessons learned? - -::: columns -:::: {.column} - -:::: -:::: column - -:::: -::: - -## Erkenntnis - -Auch in Software müssen, wie in der Realität, Zugriff fest geregelt sein. - -\vspace{1cm} -\pause - -### Dazu bieten Java die Zugrifsmodifikatoren -* `private`{.java} - Nur Zugriff innerhalb der selben Klasse -* `public`{.java} - Uneingeschränkter Zugriff - -\pause - -\begin{tikzpicture}[overlay, remember picture] - \node[rotate=-20,scale=3] at (12, 3) {\Huge \color{red} \textbf{!}}; -\end{tikzpicture} - -## Lessons learned? AUFGABE 1 - -**ZEIT: 3Min** - -Ergänze die Attribute der Klasse `Bank` und `Konto` um den Zugriffsmodifikator `private`{.java}. - -### Tipp: Syntax Deklaration von Attributden -`<Zugriffsmodifikator> <Datentype> <Attributname>;` - -## Grundsatz der Datenkapselung - -Zwei Aspekte sind wichtig: - -\vspace{0.5cm} - -> 1. **Nur** Objekt selbst sollte Zugriff auf seine Daten haben -> 2. **Benötigter** Zugriff von außen soll über von dem Objekt bereitgestellte Methoden erfolgen - -\begin{tikzpicture}[overlay, remember picture] - \only<3> { - \node[rotate=-30,scale=3] at (12, 3) {\Huge \color{red} \textbf{!}}; - } -\end{tikzpicture} - -## Datenkapselung Anwendung {.t} - -```{.java .linenos} -class Bankkonto { - public double kontostand; - private kontonummer; - - public gibBetrag() { return kontostand; } - private gibKontoNummer() { return kontonummer; } -} -``` - -## Datenkapselung Anwendung {.t} - -```{.java .linenos highlightlines=\{2\}} -class Bankkonto { - public double kontostand; - private kontonummer; - - public gibBetrag() { return kontostand; } - private gibKontoNummer() { return kontonummer; } -} -``` - -## Datenkapselung Anwendung {.t} - -```{.java .linenos highlightlines=\{2\}} -class Bankkonto { - public double kontostand; - private kontonummer; - - public gibBetrag() { return kontostand; } - private gibKontoNummer() { return kontonummer; } -} -``` - -\vspace{1cm} - -* Zeile 2: Uneingeschränkter Zugriff - -## Datenkapselung Anwendung {.t} - -```{.java .linenos highlightlines=\{2,6\}} -class Bankkonto { - public double kontostand; - private kontonummer; - - public gibBetrag() { return kontostand; } - private gibKontoNummer() { return kontonummer; } -} -``` - -\vspace{1cm} - -* Zeile 2: Uneingeschränkter Zugriff - -## Datenkapselung Anwendung {.t} - -```{.java .linenos highlightlines=\{2,6\}} -class Bankkonto { - public double kontostand; - private kontonummer; - - public gibBetrag() { return kontostand; } - private gibKontoNummer() { return kontonummer; } -} -``` - -\vspace{1cm} - -* Zeile 2: Uneingeschränkter Zugriff -* Zeile 6: Kein Zugriff von außen möglich - -## Lessons learned! - -::: columns -:::: {.column} - -:::: -:::: column - -:::: -::: - -<!-- \begin{tikzpicture}[ --> - <!-- overlay, --> - <!-- remember picture, --> - <!-- raindrop/.pic={ --> - <!-- code={\tikzset{scale=1/10} --> - <!-- \shade [shading=droplet] --> - <!-- (0,0) .. controls ++(0,-1) and ++(0,1) .. (1,-2) --> - <!-- arc (360:180:1) --> - <!-- .. controls ++(0,1) and ++(0,-1) .. (0,0) -- cycle; --> - <!-- } --> -<!-- }] --> - <!-- \only<2-> { --> - <!-- \path (3.65,3) pic {raindrop}; --> - <!-- \path (3.85,2.8) pic {raindrop}; --> - <!-- } --> - - <!-- \draw[transform canvas={shift={(8,1)}}, scale=2, line width=2pt] (3ex,2.5ex) -- (1.5ex,3ex) -- (0ex,2.5ex) to [out=-90, in=165] (1.5ex,0ex) to [out=15, in=-90] cycle (1.5ex,1.5ex) node {\Large \ding{51}}; --> -<!-- \end{tikzpicture} --> - -## Wdh. Vererbung - Auto - -{.center height=85%} - -## Wdh. Vererbung - Auto +## \faIcon{chalkboard-teacher} Wiederholung: \only<2->{Kardinalitäten} \begin{tikzpicture} \begin{class}[text width=3cm]{Auto}{0,0} @@ -189,14 +22,16 @@ class Bankkonto { \operation{...} \end{class} - \association{Auto}{1}{besteht aus >}{Bauteil}{< verbaut in}{n} + \association{Auto}{\boldred{1}}{besteht aus >}{Bauteil}{< verbaut in}{\boldred{n}} \end{tikzpicture} \vspace{1cm} -Hilft uns diese Modellierung beim Konstruieren eines Autos? +\only<-2>{\phantom{ Hilft uns diese Modellierung beim Konstruieren eines Autos? }} +\only<3->{ Hilft uns diese Modellierung beim Konstruieren eines Autos? } -## Wdh. Vererbung Spezialisierung - Auto +## \faIcon{chalkboard-teacher} Wiederholung: \only<2->{Vererbung} \only<3->{(Spezialisierung)} +\vspace{0.1cm} \begin{tikzpicture} \begin{class}[text width=3cm]{Auto}{0, 2.5} \attribute{...} @@ -227,14 +62,53 @@ Hilft uns diese Modellierung beim Konstruieren eines Autos? \attribute{...} \operation{...} \end{class} + + \node[below=0.2cm of Motor] (spez) {speziell}; + \node (allg) at (Bauteil |- spez) {allgemein}; + \draw[{Triangle[open]}-] (allg) -- (spez); +\end{tikzpicture} + +## \faIcon{desktop} Arbeitsauftrag - 15min + +* Kopiere das **Bälle** Projekt und öffne es in BlueJ +* Erzeuge einen Ball und einen Flummi und starte die *Simulation* +* Zeichne eine Klassendiagramm der Klassen `Flummi`, `Ball`, und `Kreis`. + (Die Attribute und Methoden der Klasse `Kreis` können weggelassen werden) +* Untersuche wie das Konzept der Vererbung in Java umgesetzt wurde. + +\hfill{} +*Nicht der Physik-Lehrkraft zeigen!* `\o/` + +## Klassendiagramm + +\begin{tikzpicture} + \begin{class}[text width=3cm]{Kreis}{0, 0} + \attribute{...} + \operation{...} + \end{class} + + \begin{class}[text width=4.5cm]{Ball}{5, 0} + \inherit{Kreis} + \attribute{geschwindigkeit} + \operation{Ausführen()} + \operation{SonderTaste(sondertaste)} + \operation{Taste(taste)} + \operation{Geklickt(x, y, anzahl)} + \end{class} + + \begin{class}[text width=3cm]{Flummi}{10, 0} + \inherit{Ball} + \attribute{bounceFaktor} + \operation{Ausführen()} + \end{class} \end{tikzpicture} -## Wdh. Vererbung in Java {.t} +## \faIcon{pencil-alt} Vererbung in Java {.t} Das Java Schlüsselwort ... -## Wdh. Vererbung in Java {.t} +## \faIcon{pencil-alt} Vererbung in Java {.t} Das Java Schlüsselwort `extends`{.java} drückt eine Vererbungsbeziehung zwischen zwei Klassen aus. @@ -257,10 +131,10 @@ Man spricht: "Eine Felge *ist* ein Bauteil". \pause \begin{tikzpicture}[overlay, remember picture] - \node[rotate=-30,scale=3] at (12, 3) {\Huge \color{red} \textbf{!}}; + \node[rotate=-30,scale=3] at (12, 3) {\Huge \boldred{!}}; \end{tikzpicture} -## Wdh. Vererbung in Java +## \faIcon{chalkboard-teacher} Wiederholung: Vererbung in Java ::: columns :::: {.column width=40%} @@ -273,7 +147,8 @@ class Oberklasse { zahl = n; } - public void gibZahl() { + public void gibZahl() + { return zahl; } } @@ -283,7 +158,8 @@ class Oberklasse { :::: {.column width=50%} ```java class Unterklasse extends Oberklasse { - public void Unterklasse(int n) { + public void Unterklasse(int n) + { // Oberklasse Initialisierung? } } @@ -291,7 +167,7 @@ class Unterklasse extends Oberklasse { :::: ::: -## Wdh. Vererbung in Java +## \faIcon{chalkboard-teacher} Wiederholung: Vererbung in Java ::: columns :::: {.column width=40%} @@ -304,7 +180,8 @@ class Oberklasse { zahl = n; } - public void gibZahl() { + public void gibZahl() + { return zahl; } } @@ -312,9 +189,10 @@ class Oberklasse { :::: :::: {.column width=50%} -```{.java highlightlines=\{3\}} +```{.java highlightlines=\{4\}} class Unterklasse extends Oberklasse { - public void Unterklasse(int n) { + public void Unterklasse(int n) + { super(n); } } @@ -322,13 +200,13 @@ class Unterklasse extends Oberklasse { :::: ::: -## Wdh. Vererbung in Java {.t} +## \faIcon{pencil-alt} Vererbung in Java 2. {.t} \vspace{1cm} Die Oberklasse ist über das Java Schlüsselwort ... benutzbar. -## Wdh. Vererbung in Java {.t} +## \faIcon{pencil-alt} Vererbung in Java 2. {.t} \vspace{1cm} @@ -349,248 +227,25 @@ Die Oberklasse ist über das Java Schlüsselwort `super`{.java} benutzbar. \node[rotate=-30,scale=3] at (12, 3) {\Huge \color{red} \textbf{!}}; \end{tikzpicture} -## Vererbung - Problem - -\begin{tikzpicture} - \begin{class}[text width=4cm]{Sparkonto}{0,0} - \attribute{kontostand} - \attribute{kontonummer} - \attribute{zinssatz} - \operation{Einzahlen(betrag)} - \operation{Abheben(betrag)} - \operation{KontostandGeben()} - \operation{Verzinsen()} - \end{class} - - \begin{class}[text width=4cm]{Girokonto}{5,0} - \attribute{kontostand} - \attribute{kontonummer} - \operation{Einzahlen(betrag)} - \operation{Abheben(betrag)} - \operation{KontostandGeben()} - \end{class} - - \begin{class}[text width=4cm]{Firmenkonto}{10,0} - \attribute{kontostand} - \attribute{kontonummer} - \attribute{dispokredit} - \operation{Einzahlen(betrag)} - \operation{Abheben(betrag)} - \operation{KontostandGeben()} - \operation{DispokreditSetzen(wert)} - \end{class} -\end{tikzpicture} - -\pause - -Mögliche Probleme dieser Modellierung? - -## Vererbung - Generalisierung - -\resizebox{!}{0.5\textheight}{ -\begin{tikzpicture} - \begin{class}[text width=4cm]{Sparkonto}{0,0} - \attribute{kontostand} - \attribute{kontonummer} - \attribute{zinssatz} - \operation{Einzahlen(betrag)} - \operation{Abheben(betrag)} - \operation{KontostandGeben()} - \operation{Verzinsen()} - \end{class} - - \begin{class}[text width=4cm]{Girokonto}{5,0} - \attribute{kontostand} - \attribute{kontonummer} - \operation{Einzahlen(betrag)} - \operation{Abheben(betrag)} - \operation{KontostandGeben()} - \end{class} - - \begin{class}[text width=4cm]{Firmenkonto}{10,0} - \attribute{kontostand} - \attribute{kontonummer} - \attribute{dispokredit} - \operation{Einzahlen(betrag)} - \operation{Abheben(betrag)} - \operation{KontostandGeben()} - \operation{DispokreditSetzen(wert)} - \end{class} -\end{tikzpicture} -} - -**Idee**: Auslagern der gemeinsamen Attribute und Methoden in eine Oberklasse - -**Arbeitsauftrag 3min**: Zeichne ein Klassendiagramm mit einer gemeinsamen Oberklasse - -## Generalisierung - KONTO - -\begin{tikzpicture} - \node[rotate=30,scale=3] at (0, 3) {\Huge \color{red} \textbf{!}}; - - \begin{class}[text width=4cm]{KONTO}{5,4} - \attribute{kontostand} - \attribute{kontonummer} - \operation{Einzahlen(betrag)} - \operation{Abheben(betrag)} - \operation{KontostandGeben()} - \end{class} - - \begin{class}[text width=4cm]{SPARKONTO}{0,0} - \inherit{KONTO} - \attribute{zinssatz} - \operation{Verzinsen()} - \end{class} - - - \begin{class}[text width=4cm]{GIROKONTO}{5,0} - \inherit{KONTO} - \end{class} - - \begin{class}[text width=4cm]{FIRMENKONTO}{10,0} - \inherit{KONTO} - \attribute{dispokredit} - \operation{DispokreditSetzen(wert)} - \end{class} -\end{tikzpicture} - -## Generalisierung - Java - -\small - -::: columns -:::: {.column width=50%} -```java -class Konto { - private int kontostand; - private int kontonummer; - - public void Konto(int kNr) { - kontostand = 0; - kontonummer = kNr; - } - - public void Einzahlen(int betrag) { - ... -} -``` -:::: - -:::: {.column width=50%} -```java -// Klassendefinition ? - private double zinssatz; - - public void Sparkonto(int kNr, - double zs) { - // KONTO Initialisierung? - zinssatz = zs; - } - - public void Verzinsen() { - ... -} -``` -:::: -::: - -## Generalisierung - Java - -\small - -::: columns -:::: {.column width=50%} -```java -class Konto { - private int kontostand; - private int kontonummer; - - public void Konto(int kNr) { - kontostand = 0; - kontonummer = kNr; - } - - public void Einzahlen(int betrag) { - ... -} -``` -:::: - -:::: {.column width=50%} -```{.java highlightlines=\{1\}} -class Sparkonto extends Konto { - private double zinssatz; - - public void Sparkonto(int kNr, - double zs) { - super(kNr); - zinssatz = zs; - } - - public void Verzinsen() { - ... -} -``` -:::: -::: - -## Generalisierung - Java - -\small - -::: columns -:::: {.column width=50%} -```java -class Konto { - private int kontostand; - private int kontonummer; - - public void Konto(int kNr) { - kontostand = 0; - kontonummer = kNr; - } - - public void Einzahlen(int betrag) { - ... -} -``` -:::: - -:::: {.column width=50%} -```{.java highlightlines=\{1,6\}} -class Sparkonto extends KONTO { - private double zinssatz; - - public void Sparkonto(int kNr, - double zs) { - super(kNr); - zinssatz = zs; - } - - public void Verzinsen() { - ... -} -``` -:::: -::: - ## Polymorphismus \begin{center} griechisch Vielgestaltigkeit \end{center} -{.center} +`\begin{center}`{=latex} + +`\end{center}`{=latex} -## Arbeitsauftrag Tierheimverwaltung +## \faIcon{desktop}/\faIcon{pencil-alt} Arbeitsauftrag Tierheimverwaltung - 15min -* **AUFGABE 0:** Mache dich kurz mit dem Projekt Tierheim in der Online-IDE vertraut +* **AUFGABE 0:** Kopiere das Projekt Tierheim und mache dich kurz damit vertraut. * **AUFGABE 1:** Überlege dir wie du unterschiedliche Tiere im Tierheim speicherst und setze deine Überlegung um * **AUFGABE 2:** Begründe warum Pluto (Objekt der Klasse Hund) nicht ins Tierheim aufgenommen werden kann ## Polymorphismus -*... ist die Eigenschaft, dass ein **Referenzattribut** nicht nur Objekte der als Datentyp angegebenen Klasse referenzieren kann, sondern auch Objekte **aller** zu dieser Klasse existierenden **Unterklassen**.* +> ... ist die Eigenschaft, dass ein **Referenzattribut** nicht nur Objekte der als Datentyp angegebenen Klasse referenzieren kann, sondern auch Objekte **aller** zu dieser Klasse existierenden **Unterklassen**. ## Polymorphismus @@ -602,13 +257,13 @@ griechisch Vielgestaltigkeit \attribute{...} \end{object} - \begin{object}[text width=4cm]{h1}{12,0} + \begin{object}[text width=4cm]{t1}{12,0} \instanceOf{Tier} \attribute{name="Wolle"} \attribute{geschlecht="ungewiss"} \end{object} - \begin{object}[text width=4cm]{t1}{12,5} + \begin{object}[text width=4cm]{h1}{12,5} \instanceOf{Hund} \attribute{name="Pluto" } \attribute{geschlecht="maennlich"} @@ -625,26 +280,26 @@ griechisch Vielgestaltigkeit } \end{tikzpicture} -## Arbeitsauftrag Tierheimverwaltung Fortsetzung +## \faIcon{desktop}/\faIcon{pencil-alt} Arbeitsauftrag Tierheimverwaltung Fortsetzung -* **AUFGABE 3:** Vervollständige die Klasse Hund als Spezialisierung der Klasse Tier -* **AUFGABE 4:** Implementiere die Methode `Tierheim.besuchen()` und überlege dir welche Ausgaben das Programm machen wird. Überprüfe deine Vermutung in dem du das Programm ausführst. +* **AUFGABE 3:** Vervollständige die Klasse `Hund` als Spezialisierung der Klasse `Tier` +* **AUFGABE 4:** Implementiere die Methode `Tierheim.besuchen()`{.java} und überlege dir welche Ausgaben das Programm machen wird. Überprüfe deine Vermutung in dem du das Programm ausführst. -## Polymorphismus +## \faIcon{pencil-alt} Polymorphismus -*ist die Eigenschaft, dass ein **Referenzattribut** nicht nur Objekte der als Datentyp angegebenen Klasse referenzieren kann, sondern auch Objekte **aller** zu dieser Klasse existierenden **Unterklassen**.* +> ... ist die Eigenschaft, dass ein **Referenzattribut** nicht nur Objekte der als Datentyp angegebenen Klasse referenzieren kann, sondern auch Objekte **aller** zu dieser Klasse existierenden **Unterklassen**. -\vspace{0.25cm} +\vspace{1cm} -*Wird ein **Objekt einer Unterklasse** über dieses Referenzattribut referenziert, so werden Attribute und Methoden verwendet, wie sie in **seiner Klasse** bekannt sind (und nicht die überschriebenen Methoden der Oberklasse).* +> Wird ein **Objekt einer Unterklasse** über dieses Referenzattribut referenziert, so werden Attribute und Methoden verwendet, wie sie in **dessen Klasse** bekannt sind (und nicht die überschriebenen Methoden der Oberklasse). \pause \begin{tikzpicture}[overlay, remember picture] - \node[rotate=-20,scale=3] at (12, -0.5) {\Huge \color{red} \textbf{!}}; + \node[rotate=-20,scale=3] at (12, -0.5) {\Huge \boldred{!}}; \end{tikzpicture} -## Beispiel +## \faIcon{chalkboard-teacher} Beispiel: Polymorphismus Was gibt dieses Programm aus? @@ -660,4 +315,4 @@ pluto.gibLaut(); `Wuff` ::: -Da der Polymorphismus dafür sorgt das die Methode wie sie in der Unterklasse `Hund` bekannt ist ausgeführt wird. +Da der **Polymorphismus** dafür sorgt das die Methode wie sie in der Unterklasse `Hund` bekannt ist ausgeführt wird. diff --git a/Info/23_24/05/06/10B/abfrage.md b/Info/23_24/05/06/10B/abfrage.md new file mode 100644 index 00000000..f83fc8b2 --- /dev/null +++ b/Info/23_24/05/06/10B/abfrage.md @@ -0,0 +1,28 @@ +## Widerholung + +::: {.columns align=center} +:::: {.column width=60%} +* Beschreibe knapp wie die Kollision zweier Objekte erkannt werden kann. +* Entwerfe einen Algorithmus in Pseudocode, der die Körperteile der Schlange nach dem Vorbild einer Raupe bewegt. +* Schreibe eine `for`{.java}-Schleife, die die Elemente eines Feld `feld` in umgekehrter Reihenfolge [ausgibt]{.underline}. +:::: + +:::: {.column width=40%} +{.center with=110%} +:::: +::: + + +## Lösung + +* Prüfen ob sich deren Formen überschneiden +* ``` +Für jedes Körperteile von hinten nach vorne bis zum Kopf + Setze Position des Koerperteils auf die des Vorgängers +Bewege den Kopf +``` +* ```java + for(int i = feld.length-1; i >= 0; i--) { + System.out.println(feld[i]); + } +``` diff --git a/Info/23_24/05/06/10B/img/caterpillar_movement.png b/Info/23_24/05/06/10B/img/caterpillar_movement.png new file mode 120000 index 00000000..5c075cc4 --- /dev/null +++ b/Info/23_24/05/06/10B/img/caterpillar_movement.png @@ -0,0 +1 @@ +../../../../../10/2/Snake/img/Copyrighted/caterpillar_movement.png
\ No newline at end of file diff --git a/Info/23_24/05/06/10B/schedule.md b/Info/23_24/05/06/10B/schedule.md new file mode 100644 index 00000000..f3c8ce32 --- /dev/null +++ b/Info/23_24/05/06/10B/schedule.md @@ -0,0 +1,32 @@ +--- +lang: de +geometry: margin=2cm +--- +# Polymorphismus + +* **Klasse**: 10B +* **Datum**: 06.05 + +## Lernziele + +## Verlaufplan + +--------------------------------------------------------------------------------------------------- +Zeit Phase Unterrichtsgeschehen Ziel Methode Medien +----- --------------- -------------------------------------------- ----------- ---------- --------- +7 Wdh Wiederholung Snake EA + +5 Orga Fehlersammlung LV + +5 Motivation Modellierung Auto UG + +15 Vererbung BallProjekt PA + +10 Sicherung Vererbung UG + +15 Erarbeitung Tierheim PA + +10 Sicherung Polymorphismus UG + +15 Uebung Tierheim PA +--------------------------------------------------------------------------------------------------- diff --git a/Info/23_24/05/06/10B/slides.md b/Info/23_24/05/06/10B/slides.md new file mode 100644 index 00000000..c0cea5d2 --- /dev/null +++ b/Info/23_24/05/06/10B/slides.md @@ -0,0 +1,23 @@ +--- +author: Florian Fischer +aspectratio: 169 +header-includes: | + \makeatletter + \beamer@ignorenonframefalse + \makeatother +--- + +```{.include} +abfrage.md +``` + +## {.standout} + +\centering +Erneuter Hinweis auf die Fehlersammlung unter [https://0173.drive.bycs.de/s/XGeqenxibFNuJes](https://0173.drive.bycs.de/s/XGeqenxibFNuJes). + +**Link** gibts jetzt auch im Ablage Laufwerk. + +```{.include} +topic/slides.md +``` diff --git a/Info/23_24/05/06/10B/topic b/Info/23_24/05/06/10B/topic new file mode 120000 index 00000000..96d5be61 --- /dev/null +++ b/Info/23_24/05/06/10B/topic @@ -0,0 +1 @@ +../../../../10/2/Polymorphismus
\ No newline at end of file |
