diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-04-26 15:23:29 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-04-26 15:27:07 +0200 |
| commit | f2571c4dfd1df0371fee1191589264b84db10065 (patch) | |
| tree | 9e5c04d49e2f5f2644dafc9ad7f3e48c12e81510 /Info | |
| parent | e81c04b0a3813ed837ca1831a408a32c7d01a696 (diff) | |
| download | unterricht-f2571c4dfd1df0371fee1191589264b84db10065.tar.gz unterricht-f2571c4dfd1df0371fee1191589264b84db10065.zip | |
add exercise sheet and slides_handout.md
Diffstat (limited to 'Info')
| -rw-r--r-- | Info/10/2/Polymorphismus/.gitignore | 3 | ||||
| -rw-r--r-- | Info/10/2/Polymorphismus/Makefile | 15 | ||||
| -rw-r--r-- | Info/10/2/Polymorphismus/handout.tex | 58 | ||||
| -rw-r--r-- | Info/10/2/Polymorphismus/slides.md | 40 | ||||
| -rw-r--r-- | Info/10/2/Polymorphismus/slides.tex | 856 | ||||
| -rw-r--r-- | Info/10/2/Polymorphismus/slides.vrb | 18 | ||||
| l--------- | Info/10/2/Polymorphismus/slides_handout.md | 1 |
7 files changed, 102 insertions, 889 deletions
diff --git a/Info/10/2/Polymorphismus/.gitignore b/Info/10/2/Polymorphismus/.gitignore new file mode 100644 index 00000000..79183f50 --- /dev/null +++ b/Info/10/2/Polymorphismus/.gitignore @@ -0,0 +1,3 @@ +slides.pptx +slides_handout.* +!slides_handout.md diff --git a/Info/10/2/Polymorphismus/Makefile b/Info/10/2/Polymorphismus/Makefile index 7f3c037d..0c1f2512 100644 --- a/Info/10/2/Polymorphismus/Makefile +++ b/Info/10/2/Polymorphismus/Makefile @@ -1,9 +1,18 @@ +LATEX_BASE = ../../../../latex +RUBBER_OPTS = -m lualatex:pdf --shell-escape -I "$(LATEX_BASE)" + PANDOC_FILTER_DIR = ../../../../pandoc -slides.pdf: slides.tex $(wildcard img/*) - rubber --pdf -m lualatex:pdf --shell-escape $< && rubber --clean -q $< +PANDOC_FILTERS = --lua-filter "$(PANDOC_FILTER_DIR)/center-img.lua" --lua-filter "$(PANDOC_FILTER_DIR)/include-files.lua" --no-highlight --lua-filter "$(PANDOC_FILTER_DIR)/minted.lua" +SLIDE_OPTIONS = --standalone --slide-level 2 -t beamer + +%.pdf: %.tex $(wildcard img/*) + rubber $(RUBBER_OPTS) $< && rubber --clean -q $< slides.tex: slides.md | Makefile - pandoc --standalone --slide-level 2 -t beamer --pdf-engine=lualatex --lua-filter "$(PANDOC_FILTER_DIR)/center-img.lua" --lua-filter "$(PANDOC_FILTER_DIR)/include-files.lua" --no-highlight --lua-filter "$(PANDOC_FILTER_DIR)/minted.lua" $< -o $@ + pandoc $(SLIDE_OPTIONS) --pdf-engine=lualatex $(PANDOC_FILTERS) $< -o $@ + +slides_handout.tex: slides.md | Makefile + pandoc $(SLIDE_OPTIONS) -M handout --pdf-engine=lualatex $(PANDOC_FILTERS) $< -o $@ .PHONY: clean: diff --git a/Info/10/2/Polymorphismus/handout.tex b/Info/10/2/Polymorphismus/handout.tex new file mode 100644 index 00000000..b3b9bc70 --- /dev/null +++ b/Info/10/2/Polymorphismus/handout.tex @@ -0,0 +1,58 @@ +\documentclass{handout} + +\setlength\parindent{0pt} + +\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] + +Wie wird der Konstruktor der Klasse Katze implementiert? \\[5mm] + +Welche Objekte sind bereits vorhanden? Führe das Programm aus. \\[5mm] + +\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] + +\textbf{AUFGABE 2:} Begründe warum Pluto (Objekt der Klasse Hund) nicht ins Tierheim aufgenommen werden kann. \\[5mm] + +\begin{multicols}{2} +\begin{tikzpicture}[scale=0.45] + \begin{object}[text width=3.5cm]{th1}{0,0.5} + \instanceOf{Tierheim} + \attribute{tiere[0]} + \attribute{tiere[1]} + \attribute{...} + \end{object} + + \begin{object}[text width=4cm]{h1}{12,0} + \instanceOf{Tier} + \attribute{name="Wolle"} + \attribute{geschlecht="ungewiss"} + \end{object} + + \begin{object}[text width=4cm]{t1}{12,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) {}; + \draw[line width=2pt, -latex, draw=red!80] (circle2) edge [bend right=15] (8, -0.5) {}; +\end{tikzpicture} + +\columnbreak + +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}.} + +\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} + + +\textbf{AUFGABE 3:} Vervollständige die Klasse Hund als Spezialisierung der Klasse Tier. + +\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. +\end{document} diff --git a/Info/10/2/Polymorphismus/slides.md b/Info/10/2/Polymorphismus/slides.md index 5b524b65..667ba987 100644 --- a/Info/10/2/Polymorphismus/slides.md +++ b/Info/10/2/Polymorphismus/slides.md @@ -13,6 +13,14 @@ header-includes: | \colorlet{droplet color}{blue!50!cyan} --- +## Lessons learned? AUFGABE 0 + +**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 @@ -41,6 +49,15 @@ Auch in Software müssen, wie in der Realität, Zugriff fest geregelt sein. \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: @@ -577,24 +594,25 @@ griechisch Vielgestaltigkeit ## 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 \begin{tikzpicture}[scale=0.5] - \begin{object}[text width=3.5cm]{s1}{0,0} + \begin{object}[text width=3.5cm]{th1}{0,0.5} \instanceOf{Tierheim} - \attribute{Tiere[0]} + \attribute{tiere[0]} + \attribute{tiere[1]} \attribute{...} \end{object} - \begin{object}[text width=4cm]{a1}{12,0} + \begin{object}[text width=4cm]{h1}{12,0} \instanceOf{Tier} \attribute{name="Wolle"} \attribute{geschlecht="ungewiss"} \end{object} - \begin{object}[text width=4cm]{a1}{12,5} + \begin{object}[text width=4cm]{t1}{12,5} \instanceOf{Hund} \attribute{name="Pluto" } \attribute{geschlecht="maennlich"} @@ -602,20 +620,18 @@ griechisch Vielgestaltigkeit \end{object} \only<2->{ - \node[fill=black, circle, minimum size=0.075cm] (circle) at (2.2, -1.75) {}; - } - \only<2> { + \node[fill=black, circle, minimum size=0.075cm] (circle) at (2.2, -2.35) {}; \draw[line width=2pt, -latex] (circle) edge [bend right=15] (8, -0.5) {}; } \only<3> { - \draw[line width=2pt, -latex] (circle) edge [bend left=30] (8, 4.5) {}; + \node[fill=black, circle, minimum size=0.075cm] (circle2) at (2.2, -1.4) {}; + \draw[line width=2pt, -latex] (circle2) edge [bend left=30] (8, 4.5) {}; } \end{tikzpicture} +## Arbeitsauftrag Tierheimverwaltung Fortsetzung -## Arbeitsauftrag Tierheimverwaltung Vorsetzung - -* **AUFGABE 3:** Passe die Klasse Hund entsprechend an +* **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. ## Polymorphismus diff --git a/Info/10/2/Polymorphismus/slides.tex b/Info/10/2/Polymorphismus/slides.tex deleted file mode 100644 index 17ffe186..00000000 --- a/Info/10/2/Polymorphismus/slides.tex +++ /dev/null @@ -1,856 +0,0 @@ -% Options for packages loaded elsewhere -\PassOptionsToPackage{unicode}{hyperref} -\PassOptionsToPackage{hyphens}{url} -% -\documentclass[ - ignorenonframetext, - aspectratio=169, -]{beamer} -\usepackage{pgfpages} -\setbeamertemplate{caption}[numbered] -\setbeamertemplate{caption label separator}{: } -\setbeamercolor{caption name}{fg=normal text.fg} -\beamertemplatenavigationsymbolsempty -% Prevent slide breaks in the middle of a paragraph -\widowpenalties 1 10000 -\raggedbottom -\setbeamertemplate{part page}{ - \centering - \begin{beamercolorbox}[sep=16pt,center]{part title} - \usebeamerfont{part title}\insertpart\par - \end{beamercolorbox} -} -\setbeamertemplate{section page}{ - \centering - \begin{beamercolorbox}[sep=12pt,center]{part title} - \usebeamerfont{section title}\insertsection\par - \end{beamercolorbox} -} -\setbeamertemplate{subsection page}{ - \centering - \begin{beamercolorbox}[sep=8pt,center]{part title} - \usebeamerfont{subsection title}\insertsubsection\par - \end{beamercolorbox} -} -\AtBeginPart{ - \frame{\partpage} -} -\AtBeginSection{ - \ifbibliography - \else - \frame{\sectionpage} - \fi -} -\AtBeginSubsection{ - \frame{\subsectionpage} -} -\usepackage{amsmath,amssymb} -\usepackage{iftex} -\ifPDFTeX - \usepackage[T1]{fontenc} - \usepackage[utf8]{inputenc} - \usepackage{textcomp} % provide euro and other symbols -\else % if luatex or xetex - \usepackage{unicode-math} % this also loads fontspec - \defaultfontfeatures{Scale=MatchLowercase} - \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1} -\fi -\usepackage{lmodern} -\usetheme[]{Rochester} -\ifPDFTeX\else - % xetex/luatex font selection -\fi -% Use upquote if available, for straight quotes in verbatim environments -\IfFileExists{upquote.sty}{\usepackage{upquote}}{} -\IfFileExists{microtype.sty}{% use microtype if available - \usepackage[]{microtype} - \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts -}{} -\makeatletter -\@ifundefined{KOMAClassName}{% if non-KOMA class - \IfFileExists{parskip.sty}{% - \usepackage{parskip} - }{% else - \setlength{\parindent}{0pt} - \setlength{\parskip}{6pt plus 2pt minus 1pt}} -}{% if KOMA class - \KOMAoptions{parskip=half}} -\makeatother -\usepackage{xcolor} -\newif\ifbibliography -\usepackage{graphicx} -\makeatletter -\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} -\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi} -\makeatother -% Scale images if necessary, so that they will not overflow the page -% margins by default, and it is still possible to overwrite the defaults -% using explicit options in \includegraphics[width, height, ...]{} -\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio} -% Set default figure placement to htbp -\makeatletter -\def\fps@figure{htbp} -\makeatother -\setlength{\emergencystretch}{3em} % prevent overfull lines -\providecommand{\tightlist}{% - \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} -\setcounter{secnumdepth}{-\maxdimen} % remove section numbering -\usepackage[school]{pgf-umlcd} -\usepackage{unicode-math} -\usepackage{pifont} -\usepackage{tikz} -\usepackage{minted} -\usetikzlibrary{calc} -\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} -\ifLuaTeX - \usepackage{selnolig} % disable illegal ligatures -\fi -\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}} -\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available -\urlstyle{same} -\hypersetup{ - pdfauthor={Florian Fischer}, - hidelinks, - pdfcreator={LaTeX via pandoc}} - -\author{Florian Fischer} -\date{} - -\begin{document} - -\begin{frame}[fragile]{Lessons learned?} -\protect\hypertarget{lessons-learned}{} -\begin{columns}[T] -\begin{column}{0.48\textwidth} -\includegraphics{../Datenkapselung/img/Computer-hacker.jpg} -\end{column} - -\begin{column}{0.48\textwidth} -\includegraphics{../Datenkapselung/img/Bank.png} -\end{column} -\end{columns} -\end{frame} - -\begin{frame}[fragile]{Erkenntnis} -\protect\hypertarget{erkenntnis}{} -Auch in Software müssen, wie in der Realität, Zugriff fest geregelt -sein. - -\vspace{1cm} -\pause - -\begin{block}{Dazu bieten Java die Zugrifsmodifikatoren} -\protect\hypertarget{dazu-bieten-java-die-zugrifsmodifikatoren}{} -\begin{itemize} -\tightlist -\item - \mintinline[]{java}{private} - Nur Zugriff innerhalb der selben Klasse -\item - \mintinline[]{java}{public} - Uneingeschränkter Zugriff -\end{itemize} - -\pause - -\begin{tikzpicture}[overlay, remember picture] - \node[rotate=-20,scale=3] at (12, 3) {\Huge \color{red} \textbf{!}}; -\end{tikzpicture} -\end{block} -\end{frame} - -\begin{frame}[fragile]{Grundsatz der Datenkapselung} -\protect\hypertarget{grundsatz-der-datenkapselung}{} -Zwei Aspekte sind wichtig: - -\vspace{0.5cm} - -\begin{enumerate}[<+->] -\tightlist -\item - \textbf{Nur} Objekt selbst sollte Zugriff auf seine Daten haben -\item - \textbf{Benötigter} Zugriff von außen soll über von dem Objekt - bereitgestellte Methoden erfolgen -\end{enumerate} - -\begin{tikzpicture}[overlay, remember picture] - \only<3> { - \node[rotate=-30,scale=3] at (12, 3) {\Huge \color{red} \textbf{!}}; - } -\end{tikzpicture} -\end{frame} - -\begin{frame}[t,fragile]{Datenkapselung Anwendung} -\protect\hypertarget{datenkapselung-anwendung}{} -\begin{minted}[linenos,autogobble]{java} -class Bankkonto { - public double kontostand; - private kontonummer; - - public gibBetrag() { return kontostand; } - private gibKontoNummer() { return kontonummer; } -} -\end{minted} -\end{frame} - -\begin{frame}[t,fragile]{Datenkapselung Anwendung} -\protect\hypertarget{datenkapselung-anwendung-1}{} -\begin{minted}[linenos,highlightlines={2},autogobble]{java} -class Bankkonto { - public double kontostand; - private kontonummer; - - public gibBetrag() { return kontostand; } - private gibKontoNummer() { return kontonummer; } -} -\end{minted} -\end{frame} - -\begin{frame}[t,fragile]{Datenkapselung Anwendung} -\protect\hypertarget{datenkapselung-anwendung-2}{} -\begin{minted}[linenos,highlightlines={2},autogobble]{java} -class Bankkonto { - public double kontostand; - private kontonummer; - - public gibBetrag() { return kontostand; } - private gibKontoNummer() { return kontonummer; } -} -\end{minted} - -\vspace{1cm} - -\begin{itemize} -\tightlist -\item - Zeile 2: Uneingeschränkter Zugriff -\end{itemize} -\end{frame} - -\begin{frame}[t,fragile]{Datenkapselung Anwendung} -\protect\hypertarget{datenkapselung-anwendung-3}{} -\begin{minted}[linenos,highlightlines={2,6},autogobble]{java} -class Bankkonto { - public double kontostand; - private kontonummer; - - public gibBetrag() { return kontostand; } - private gibKontoNummer() { return kontonummer; } -} -\end{minted} - -\vspace{1cm} - -\begin{itemize} -\tightlist -\item - Zeile 2: Uneingeschränkter Zugriff -\end{itemize} -\end{frame} - -\begin{frame}[t,fragile]{Datenkapselung Anwendung} -\protect\hypertarget{datenkapselung-anwendung-4}{} -\begin{minted}[linenos,highlightlines={2,6},autogobble]{java} -class Bankkonto { - public double kontostand; - private kontonummer; - - public gibBetrag() { return kontostand; } - private gibKontoNummer() { return kontonummer; } -} -\end{minted} - -\vspace{1cm} - -\begin{itemize} -\tightlist -\item - Zeile 2: Uneingeschränkter Zugriff -\item - Zeile 6: Kein Zugriff von außen möglich -\end{itemize} -\end{frame} - -\begin{frame}[fragile]{Lessons learned!} -\protect\hypertarget{lessons-learned-1}{} -\begin{columns}[T] -\begin{column}{0.48\textwidth} -\includegraphics{../Datenkapselung/img/Computer-hacker.jpg} -\end{column} - -\begin{column}{0.48\textwidth} -\includegraphics{../Datenkapselung/img/Bank.png} -\end{column} -\end{columns} - -\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} -\end{frame} - -\begin{frame}[fragile]{Wdh. Vererbung - Auto} -\protect\hypertarget{wdh.-vererbung---auto}{} -\hfill\break{\centering\includegraphics[width=\textwidth,height=0.85\textheight]{img/Copyrighted/car_explosion.png}\par} -\end{frame} - -\begin{frame}[fragile]{Wdh. Vererbung - Auto} -\protect\hypertarget{wdh.-vererbung---auto-1}{} -\begin{tikzpicture} - \begin{class}[text width=3cm]{AUTO}{0,0} - \attribute{...} - \operation{...} - \end{class} - - \begin{class}[text width=3cm]{BAUTEIL}{9,0} - \attribute{...} - \operation{...} - \end{class} - - \association{AUTO}{1}{besteht aus >}{BAUTEIL}{< verbaut in}{n} -\end{tikzpicture} - -\vspace{1cm} - -Hilft uns diese Modellierung beim Konstruieren eines Autos? -\end{frame} - -\begin{frame}[fragile]{Wdh. Vererbung Spezialisierung - Auto} -\protect\hypertarget{wdh.-vererbung-spezialisierung---auto}{} -\begin{tikzpicture} - \begin{class}[text width=3cm]{AUTO}{0, 2.5} - \attribute{...} - \operation{...} - \end{class} - - \begin{class}[text width=3cm]{BAUTEIL}{5, 2.5} - \attribute{...} - \operation{...} - \end{class} - - \association{AUTO}{1}{}{BAUTEIL}{n}{} - - \begin{class}[text width=4cm]{Motor}{10, 0} - \inherit{BAUTEIL} - \attribute{...} - \operation{...} - \end{class} - - \begin{class}[text width=4cm]{Felge}{10, 2.5} - \inherit{BAUTEIL} - \attribute{...} - \operation{...} - \end{class} - - \begin{class}[text width=4cm]{Windschutzscheibe}{10, 5} - \inherit{BAUTEIL} - \attribute{...} - \operation{...} - \end{class} -\end{tikzpicture} -\end{frame} - -\begin{frame}[t,fragile]{Wdh. Vererbung in Java} -\protect\hypertarget{wdh.-vererbung-in-java}{} -Das Java Schlüsselwort \ldots{} -\end{frame} - -\begin{frame}[t,fragile]{Wdh. Vererbung in Java} -\protect\hypertarget{wdh.-vererbung-in-java-1}{} -Das Java Schlüsselwort \mintinline[]{java}{extends} drückt eine -Vererbungsbeziehung zwischen zwei Klassen aus. - -\vspace{0.5cm} - -\pause - -\begin{block}{Syntax der Klassendefinition} -\protect\hypertarget{syntax-der-klassendefinition}{} -\mintinline[]{java}|class Unterklasse extends Oberklasse {...}| -\end{block} - -\vspace{0.5cm} - -\pause - -Die Unterklasse erbt alle Methoden und Attribute der Oberklasse.\\ -Man spricht: ``Eine Felge \emph{ist} ein Bauteil''. - -\pause - -\begin{tikzpicture}[overlay, remember picture] - \node[rotate=-30,scale=3] at (12, 3) {\Huge \color{red} \textbf{!}}; -\end{tikzpicture} -\end{frame} - -\begin{frame}[fragile]{Wdh. Vererbung in Java} -\protect\hypertarget{wdh.-vererbung-in-java-2}{} -\begin{columns}[T] -\begin{column}{0.4\textwidth} -\begin{minted}[autogobble]{java} -class Oberklasse { - private int zahl; - - public void Oberklasse(int n) - { - zahl = n; - } - - public void gibZahl() { - return zahl; - } -} -\end{minted} -\end{column} - -\begin{column}{0.5\textwidth} -\begin{minted}[autogobble]{java} -class Unterklasse extends Oberklasse { - public void Unterklasse(int n) { - // Oberklasse Initialisierung? - } -} -\end{minted} -\end{column} -\end{columns} -\end{frame} - -\begin{frame}[fragile]{Wdh. Vererbung in Java} -\protect\hypertarget{wdh.-vererbung-in-java-3}{} -\begin{columns}[T] -\begin{column}{0.4\textwidth} -\begin{minted}[autogobble]{java} -class Oberklasse { - private int zahl; - - public void Oberklasse(int n) - { - zahl = n; - } - - public void gibZahl() { - return zahl; - } -} -\end{minted} -\end{column} - -\begin{column}{0.5\textwidth} -\begin{minted}[highlightlines={3},autogobble]{java} -class Unterklasse extends Oberklasse { - public void Unterklasse(int n) { - super(n); - } -} -\end{minted} -\end{column} -\end{columns} -\end{frame} - -\begin{frame}[t,fragile]{Wdh. Vererbung in Java} -\protect\hypertarget{wdh.-vererbung-in-java-4}{} -\vspace{1cm} - -Die Oberklasse ist über das Java Schlüsselwort \ldots{} benutzbar. -\end{frame} - -\begin{frame}[t,fragile]{Wdh. Vererbung in Java} -\protect\hypertarget{wdh.-vererbung-in-java-5}{} -\vspace{1cm} - -Die Oberklasse ist über das Java Schlüsselwort -\mintinline[]{java}{super} benutzbar. - -\vspace{1cm} -\pause - -\begin{block}{Beispiele} -\protect\hypertarget{beispiele}{} -\begin{itemize} -\tightlist -\item - \mintinline[]{java}{super(...)} Konstruktoraufruf der Oberklasse -\item - \mintinline[]{java}{super.zahl} Attribut der Oberklasse -\item - \mintinline[]{java}{super.zahlGeben()} Methodenaufruf der Oberklasse -\end{itemize} - -\pause - -\begin{tikzpicture}[overlay, remember picture] - \node[rotate=-30,scale=3] at (12, 3) {\Huge \color{red} \textbf{!}}; -\end{tikzpicture} -\end{block} -\end{frame} - -\begin{frame}[fragile]{Vererbung - Problem} -\protect\hypertarget{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? -\end{frame} - -\begin{frame}[fragile]{Vererbung - Generalisierung} -\protect\hypertarget{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} -} - -\textbf{Idee}: Auslagern der gemeinsamen Attribute und Methoden in eine -Oberklasse - -\textbf{Arbeitsauftrag 3min}: Zeichne ein Klassendiagramm mit einer -gemeinsamen Oberklasse -\end{frame} - -\begin{frame}[fragile]{Generalisierung - KONTO} -\protect\hypertarget{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} -\end{frame} - -\begin{frame}[fragile]{Generalisierung - Java} -\protect\hypertarget{generalisierung---java}{} -\small - -\begin{columns}[T] -\begin{column}{0.5\textwidth} -\begin{minted}[autogobble]{java} -class Konto { - private int kontostand; - private int kontonummer; - - public void Konto(int kNr) { - kontostand = 0; - kontonummer = kNr; - } - - public void Einzahlen(int betrag) { - ... -} -\end{minted} -\end{column} - -\begin{column}{0.5\textwidth} -\begin{minted}[autogobble]{java} -// Klassendefinition ? - private double zinssatz; - - public void Sparkonto(int kNr, - double zs) { - // KONTO Initialisierung? - zinssatz = zs; - } - - public void Verzinsen() { - ... -} -\end{minted} -\end{column} -\end{columns} -\end{frame} - -\begin{frame}[fragile]{Generalisierung - Java} -\protect\hypertarget{generalisierung---java-1}{} -\small - -\begin{columns}[T] -\begin{column}{0.5\textwidth} -\begin{minted}[autogobble]{java} -class Konto { - private int kontostand; - private int kontonummer; - - public void Konto(int kNr) { - kontostand = 0; - kontonummer = kNr; - } - - public void Einzahlen(int betrag) { - ... -} -\end{minted} -\end{column} - -\begin{column}{0.5\textwidth} -\begin{minted}[highlightlines={1},autogobble]{java} -class Sparkonto extends Konto { - private double zinssatz; - - public void Sparkonto(int kNr, - double zs) { - super(kNr); - zinssatz = zs; - } - - public void Verzinsen() { - ... -} -\end{minted} -\end{column} -\end{columns} -\end{frame} - -\begin{frame}[fragile]{Generalisierung - Java} -\protect\hypertarget{generalisierung---java-2}{} -\small - -\begin{columns}[T] -\begin{column}{0.5\textwidth} -\begin{minted}[autogobble]{java} -class Konto { - private int kontostand; - private int kontonummer; - - public void Konto(int kNr) { - kontostand = 0; - kontonummer = kNr; - } - - public void Einzahlen(int betrag) { - ... -} -\end{minted} -\end{column} - -\begin{column}{0.5\textwidth} -\begin{minted}[highlightlines={1,6},autogobble]{java} -class Sparkonto extends KONTO { - private double zinssatz; - - public void Sparkonto(int kNr, - double zs) { - super(kNr); - zinssatz = zs; - } - - public void Verzinsen() { - ... -} -\end{minted} -\end{column} -\end{columns} -\end{frame} - -\begin{frame}[fragile]{Polymorphismus} -\protect\hypertarget{polymorphismus}{} -\begin{center} -griechisch Vielgestaltigkeit -\end{center} - -\hfill\break{\centering\includegraphics{img/wolpertinger}\par} -\end{frame} - -\begin{frame}[fragile]{Arbeitsauftrag Tierheimverwaltung} -\protect\hypertarget{arbeitsauftrag-tierheimverwaltung}{} -\begin{itemize} -\tightlist -\item - \textbf{AUFGABE 0:} Mach dich Kurz mit dem Projekt Tierheim in der - Online-IDE vertraut -\item - \textbf{AUFGABE 1:} Überlege dir wie du unterschiedliche Tiere im - Tierheim speicherst und setze deine Überlegung um -\item - \textbf{AUFGABE 2:} Überlege dir warum Pluto (Objekte der Klasse Hund) - nicht ins Tierheim aufgenommen werden können -\end{itemize} -\end{frame} - -\begin{frame}[fragile]{Polymorphismus} -\protect\hypertarget{polymorphismus-1}{} -\emph{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}.} -\end{frame} - -\begin{frame}[fragile]{Polymorphismus} -\protect\hypertarget{polymorphismus-2}{} -\begin{tikzpicture}[scale=0.5] - \begin{object}[text width=3.5cm]{s1}{0,0} - \instanceOf{Tierheim} - \attribute{Tiere[0]} - \attribute{...} - \end{object} - - \begin{object}[text width=4cm]{a1}{12,0} - \instanceOf{Tier} - \attribute{name="Wolle"} - \attribute{geschlecht="ungewiss"} - \end{object} - - \begin{object}[text width=4cm]{a1}{12,5} - \instanceOf{Hund} - \attribute{name="Pluto" } - \attribute{geschlecht="maennlich"} - \attribute{rasse="comic"} - \end{object} - - \only<2->{ - \node[fill=black, circle, minimum size=0.075cm] (circle) at (2.2, -1.75) {}; - } - \only<2> { - \draw[line width=2pt, -latex] (circle) edge [bend right=15] (8, -0.5) {}; - } - \only<3> { - \draw[line width=2pt, -latex] (circle) edge [bend left=30] (8, 4.5) {}; - } -\end{tikzpicture} -\end{frame} - -\begin{frame}[fragile]{Arbeitsauftrag Tierheimverwaltung Vorsetzung} -\protect\hypertarget{arbeitsauftrag-tierheimverwaltung-vorsetzung}{} -\begin{itemize} -\tightlist -\item - \textbf{AUFGABE 3:} Passe die Klasse Hund entsprechend an -\item - \textbf{AUFGABE 4:} Implementiere die Methode - \mintinline[]{text}{Tierheim.besuchen()} und überlege dir welche - Ausgaben das Programm machen wird. Überprüfe deine Vermutung in dem du - das Programm ausführst. -\end{itemize} -\end{frame} - -\begin{frame}[fragile]{Polymorphismus} -\protect\hypertarget{polymorphismus-3}{} -\emph{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{0.25cm} - -\emph{Wird ein \textbf{Objekt einer 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).} - -\pause - -\begin{tikzpicture}[overlay, remember picture] - \node[rotate=-20,scale=3] at (12, -0.5) {\Huge \color{red} \textbf{!}}; -\end{tikzpicture} -\end{frame} - -\begin{frame}[fragile]{Beispiel} -\protect\hypertarget{beispiel}{} -Was gibt dieses Programm aus? - -\begin{minted}[autogobble]{java} -Tier pluto = new Hund("pluto", "maennlich", "comic"); -pluto.gibLaut(); -\end{minted} - -\pause - -\begin{block}{Ausgabe} -\protect\hypertarget{ausgabe}{} -\mintinline[]{text}{Wuff} -\end{block} - -Da der Polymorphismus dafür sorgt das die Methode wie sie in der -Unterklasse \mintinline[]{text}{Hund} bekannt ist ausgeführt wird. -\end{frame} - -\end{document} diff --git a/Info/10/2/Polymorphismus/slides.vrb b/Info/10/2/Polymorphismus/slides.vrb deleted file mode 100644 index 7fbefcf1..00000000 --- a/Info/10/2/Polymorphismus/slides.vrb +++ /dev/null @@ -1,18 +0,0 @@ -\frametitle{Beispiel} -\protect\hypertarget{beispiel}{} -Was gibt dieses Programm aus? - -\begin{minted}[autogobble]{java} -Tier pluto = new Hund("pluto", "maennlich", "comic"); -pluto.gibLaut(); -\end{minted} - -\pause - -\begin{block}{Ausgabe} -\protect\hypertarget{ausgabe}{} -\mintinline[]{text}{Wuff} -\end{block} - -Da der Polymorphismus dafür sorgt das die Methode wie sie in der -Unterklasse \mintinline[]{text}{Hund} bekannt ist ausgeführt wird. diff --git a/Info/10/2/Polymorphismus/slides_handout.md b/Info/10/2/Polymorphismus/slides_handout.md new file mode 120000 index 00000000..8f9cd79f --- /dev/null +++ b/Info/10/2/Polymorphismus/slides_handout.md @@ -0,0 +1 @@ +slides.md
\ No newline at end of file |
