-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.tex
More file actions
executable file
·314 lines (249 loc) · 6.33 KB
/
3.tex
File metadata and controls
executable file
·314 lines (249 loc) · 6.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
\documentclass{beamer}
\usepackage{ngerman}
\usepackage{listings}
\usepackage {ulem}
\usetheme{Madrid}
\title{Programmieren Tutorium}
\author{Florian Tobias Schandinat}
\date{8.11.2010}
\institute{FTS}
\definecolor{mygreen}{RGB}{0,128,0}
\definecolor{mybrown}{RGB}{128,0,0}
\definecolor{mygray}{RGB}{240,240,240}
\lstset{language=Java,
backgroundcolor=\color{mygray},
basicstyle=\tiny\ttfamily,
keywordstyle=\color{blue},
stringstyle=\color{mybrown},
commentstyle=\color{gray},
numbers=left,
numberstyle=\color{mygreen},
frame=single,
tabsize=4,
showstringspaces=false,
xleftmargin=3.5em,
xrightmargin=2em}
\begin{document}
\begin{frame}
\frametitle{Willkommen}
\pause
\begin{alertblock}{Letztes Mal}
\begin{itemize}
\item Variablen\\
\item Einfache Operationen\\
\item Methoden - Crashkurs
\end{itemize}
\end{alertblock}
\pause
\begin{block}{Dieses Mal}
\begin{itemize}
\item Konstruktoren und \texttt{final}\\
\item Programmablauf\\
\item Methoden -- Vertiefung\\
\item Geheimnisprinzip -- \texttt{public}, \texttt{protected}, \texttt{private}
\end{itemize}
\end{block}
\pause
\begin{exampleblock}{N"achstes Mal}
\begin{itemize}
\item Kontrollfluss\\
\item Tests
\end{itemize}
\end{exampleblock}
\end{frame}
\begin{frame}
\frametitle{Fazit: 1. "Ubungsblatt}
\begin{block}{Anmerkungen}
\begin{itemize}
\item Es ist immer besser, wenn eure L"osung kompiliert
\item Bezeichner sollen sorgf"altig gew"ahlt werden
\end{itemize}
\end{block}
\pause
\begin{block}{Musterl"osung}
inklusive JavaDoc
\end{block}
\end{frame}
\begin{frame}
\frametitle{Konstruktoren -- Einleitung}
\begin{block}{Wir finden Initialisierung toll...}
\pause
da Attribute und Variablen dann direkt den gewollten Wert haben\pause\\
Um dies auch f"ur komplexe Objekte erm"oglichen zu k"onnen haben wir Konstruktoren!\\[0.5em]
Beispiel: Initialisierung von komplexen Zahlen
\end{block}
\pause
\begin{block}{Konstruktoren -- "Uberblick}
\begin{itemize}
\item dienen dazu ein Objekt zu initialisieren\\
\item sind generell sehr "ahnlich zu Methoden\\
\item besitzen jedoch \alert{keinen R"uckgabetyp} und geben auch nichts zur"uck\\
\item k"onnen aber Parameter haben
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[containsverbatim]
\frametitle{Konstruktoren -- Beispiel}
\begin{lstlisting}
class Counter {
int count;
Counter() {
count = 1;
}
Counter(int startcount) {
count = startcount;
}
}
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{Konstruktoren -- Wie funktioniert das?}
\begin{block}{\texttt{new}}
\texttt{new} legt ein Objekt an und initialisert es mit dem passenden Konstruktor
Dieser wird ausgew"ahlt aufgrund
\begin{itemize}
\item der Klasse\\
\item der Parameteranzahl\\
\item der Reinfolge der Parametertypen
\end{itemize}
\alert{Parameternamen sind nicht relevant!}
\end{block}
\pause
\begin{block}{Beispiele}
\lstinline|Counter countA = new Counter();|\\
\lstinline|Counter countB = new Counter(0);|
\end{block}
\end{frame}
\begin{frame}
\frametitle{\texttt{final}}
\begin{block}{Einleitung}
\texttt{final} dient zur Deklaration von Konstanten, die zur Laufzeit nicht ver"andert werden k"onnen\\
Es kann bei der Deklaration Attributen/Variablen vorangestellt werden\\
Wenn es in Verbindung mit \texttt{static} auftaucht, verwenden wir nur Gro"sbuchstaben f"ur den Bezeichner\\
Beispiele:\\
\lstinline|final static double PI = 3.14;|\\
\lstinline|final double epsilon = 1E-20;|
\end{block}
\pause
\begin{block}{\texttt{final} und Konstruktoren}
In Konstruktoren k"onnen (und m"ussen) konstante Attribute der Klasse gesetzt werden, sofern nicht bereits eine Zuweisung besteht
\end{block}
\end{frame}
\begin{frame}[containsverbatim]
\frametitle{Konstruktoren -- Beispiel mit \texttt{final}}
\begin{lstlisting}
class Complex {
final double re;
final double im;
Complex() {
re = 0;
im = 0;
}
Complex(double re) {
this.re = re;
im = 0;
}
Complex(double re, double im) {
this.re = re;
this.im = im;
}
}
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{"Ubung}
\begin{center}
\textbf{\Huge Auto: Aufgabe 1}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Programmablauf}
\lstinputlisting{examples/stripped/Statistik.java}
\pause
\begin{block}{\texttt{java Beispiel2Statistik}}
Was passiert?
\end{block}
\end{frame}
\begin{frame}[containsverbatim]
\frametitle{Methoden -- Vertiefung}
\begin{block}{"Uberladen}
Wie bei Konstruktoren ist es auch bei Methoden m"oglich, Methoden mit gleichen Namen aufgrund von Parameteranzahl und Parametertypen zu unterscheiden
\end{block}
\begin{block}{Beispiel}
\begin{lstlisting}
boolean isZero(int value) {
return value == 0;
}
boolean isZero(double value) {
return Math.abs(value) <= 1E-30;
}
boolean isZero(String value) {
return isZero(value.length());
}
\end{lstlisting}
\end{block}
\end{frame}
\begin{frame}
\frametitle{Geheimnisprinzip}
\begin{block}{Ziel}
Wiederverwendbarkeit und Wartbarkeit
\end{block}
\pause
\begin{block}{Lokalit"atsprinzip}
"Anderungen sollen nur lokale Auswirkungen haben
\end{block}
\pause
\begin{block}{Folgerung}
Daher erlauben wir nur Zugriff (von au"serhalb der Klasse) auf Attribute, Konstanten und Methoden wenn es erforderlich ist
\begin{description}
\item[\texttt{public}] Zugriff aus jeder Klasse m"oglich
\item[\texttt{protected}] Zugriff von innerhalb der Klasse und aus Unterklassen (sp"ater) erlaubt
\item[\texttt{private}] Zugriff nur von innerhalb der Klasse erlaubt
\end{description}
\end{block}
\end{frame}
\begin{frame}[containsverbatim]
\frametitle{Geheimnisprinzip -- Beispiel}
\begin{lstlisting}
public class Counter {
private int count;
public Counter() {
count = 1;
}
public Counter(int count) {
this.count = count;
}
public int getCount() {
return count;
}
public void incrementCounter() {
count = count + 1;
}
public void decrementCounter() {
count = count - 1;
}
public boolean isZero() {
return count == 0;
}
}
\end{lstlisting}
\end{frame}
\begin{frame}
\frametitle{"Ubung}
\begin{center}
\textbf{\Huge Auto: Aufgabe 2}
\end{center}
\end{frame}
\begin{frame}
\frametitle{Ende}
\begin{block}{TODO}
\begin{enumerate}
\item Einreichen einer L"osung f"ur das 2. "Ubungsblatt im Praktomat bis \alert{22.11.2010, 13:00}
\item Anmelden f"ur den "Ubungsschein auf https://studium.kit.edu/ bis \alert{31.3.2011}
\end{enumerate}
\end{block}
\begin{block}{Vielen Dank f"ur die Aufmerksamkeit!}
...und viel Spa"s beim Programmieren :)
\end{block}
\end{frame}
\end{document}