8000 Added slides for sixth session · estimand/intro-to-cpp@5e0a77a · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e0a77a

Browse files
committed
Added slides for sixth session
1 parent dcbf841 commit 5e0a77a

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

06_oop/slides/oop.pdf

18.5 KB
Binary file not shown.

06_oop/slides/oop.tex

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
\input{../../_common/preamble}
2+
3+
\title{Object-oriented programming}
4+
5+
\begin{document}
6+
7+
\maketitle
8+
9+
\begin{frame}{Classes and objects}
10+
\begin{block}{Class}
11+
\begin{itemize}
12+
\item The blueprint for an object
13+
\item Encapsulates \alert{state} and \alert{behaviour}
14+
\end{itemize}
15+
\end{block}
16+
\begin{block}{Object}
17+
\begin{itemize}
18+
\item An instance of a class
19+
\item Holds data and functions
20+
\end{itemize}
21+
\end{block}
22+
\end{frame}
23+
24+
\begin{frame}{Abstraction}
25+
\begin{block}{Classes should\ldots}
26+
\begin{itemize}
27+
\item Provide only essential information to the external world
28+
\item Hide any internal implementation details
29+
\end{itemize}
30+
\end{block}
31+
\end{frame}
32+
33+
\begin{frame}{Inheritance and polymorphism}
34+
\begin{block}{Classes can\ldots}
35+
\begin{itemize}
36+
\item Reuse code by inheriting from another class
37+
\item Redefine functions through polymorphism
38+
\item Define the meaning of operators through overloading
39+
\end{itemize}
40+
\end{block}
41+
\end{frame}
42+
43+
\begin{frame}[fragile]{Defining a new class}
44+
\begin{onlyenv}<1>
45+
\begin{block}{Definition}
46+
\begin{cpp}
47+
class Rectangle {
48+
int width, height;
49+
public:
50+
Rectangle(int, int);
51+
int area(void);
52+
}; // Mind the semicolon!
53+
\end{cpp}
54+
\end{block}
55+
\end{onlyenv}
56+
\begin{onlyenv}<2>
57+
\begin{block}{Implementation}
58+
\begin{cpp}
59+
Rectangle::Rectangle(int w, int h) {
60+
width = w;
61+
height = h;
62+
}
63+
64+
Rectangle::area() {
65+
return width * height;
66+
}
67+
\end{cpp}
68+
\end{block}
69+
\end{onlyenv}
70+
\end{frame}
71+
72+
\begin{frame}[fragile]{Don't overuse classes and objects!}
73+
\begin{itemize}
74+
\item OOP can be overkill (especially for small programs)
75+
\item Classes make your code more verbose
76+
\item Try \mintinline{cpp}{struct}s if you just need `data containers'
77+
\end{itemize}
78+
\end{frame}
79+
80+
\end{document}
81+

0 commit comments

Comments
 (0)
0