Skip to content

Commit 998790c

Browse files
Small improvements to OO slides
Co-authored-by: Stephan Hageboeck <stephan.hageboeck@cern.ch>
1 parent 34d03bc commit 998790c

File tree

5 files changed

+32
-35
lines changed

5 files changed

+32
-35
lines changed

talk/objectorientation/advancedoo.tex

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353

5454
\begin{frame}[fragile]
5555
\frametitlecpp[98]{Inheritance privacy and polymorphism}
56-
\begin{block}{Only public inheritance is visible to code outside the class}
56+
\begin{block}{Only public base classes are visible to outside code}
5757
\begin{itemize}
58-
\item private and protected are not
58+
\item private and protected bases are not
5959
\item this may restrict usage of polymorphism
6060
\end{itemize}
6161
\end{block}
@@ -187,7 +187,7 @@
187187
\end{itemize}
188188
\item they also imply extra storage and an extra indirection
189189
\begin{itemize}
190-
\item practically the object stores a pointer to the correct method
190+
\item practically, the object stores a pointer to the correct method
191191
\item in a so-called ``virtual table'' (``vtable'')
192192
\end{itemize}
193193
\end{itemize}
@@ -491,9 +491,12 @@
491491
\frametitlecpp[98]{Virtual inheritance}
492492
\begin{block}{Solution}
493493
\begin{itemize}
494-
\item inheritance can be {\it virtual} or not
495-
\item {\it virtual} inheritance will ``share'' parents
496-
\item standard inheritance will replicate them
494+
\item inheritance can be \cppinline{virtual} or not
495+
\begin{itemize}
496+
\item \cppinline{virtual} inheritance will ``share'' parents
497+
\item standard inheritance will replicate them
498+
\end{itemize}
499+
\item most derived class will call the virtual base class's constructor
497500
\end{itemize}
498501
\begin{cppcode}
499502
class Text : public virtual Drawable {...};
@@ -528,19 +531,19 @@
528531

529532
\begin{frame}[fragile]
530533
\frametitlecpp[98]{Multiple inheritance advice}
531-
\begin{block}{Do not use multiple inheritance}
534+
\begin{goodpractice}{Avoid multiple inheritance}
532535
\begin{itemize}
533536
\item Except for inheriting from interfaces
534-
\item and for rare special cases
537+
\item And for rare special cases
535538
\end{itemize}
536-
\end{block}
539+
\end{goodpractice}
537540
\pause
538-
\begin{alertblock}{Do not use diamond shapes}
541+
\begin{goodpractice}{Absolutely avoid diamond-shaped inheritance}
539542
\begin{itemize}
540543
\item This is a sign that your architecture is not correct
541544
\item In case you are tempted, think twice and change your mind
542545
\end{itemize}
543-
\end{alertblock}
546+
\end{goodpractice}
544547
\end{frame}
545548

546549
\begin{frame}[fragile]
@@ -556,10 +559,3 @@
556559
\end{itemize}
557560
\end{exerciseWithShortcut}
558561
\end{frame}
559-
560-
\begin{frame}[fragile]
561-
\frametitlecpp[98]{Virtual inheritance}
562-
\begin{alertblock}{Warning}
563-
in case of virtual inheritance it is the most derived class that calls the virtual base class's constructor
564-
\end{alertblock}
565-
\end{frame}

talk/objectorientation/allocations.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
\frametitlecpp[98]{Object allocation on the stack}
4848
\begin{block}{On the stack}
4949
\begin{itemize}
50-
\item objects are created when declared (constructor called)
50+
\item objects are created on variable definition (constructor called)
5151
\item objects are destructed when out of scope (destructor is called)
5252
\end{itemize}
5353
\end{block}

talk/objectorientation/constructors.tex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
\end{cppcode*}
2525
\columnbreak
2626
\begin{cppcode*}{gobble=2,firstnumber=10}
27-
// note special notation for
27+
// note: special notation for
2828
// initialization of members
2929
MyFirstClass() : a(0) {}
3030

@@ -81,7 +81,7 @@
8181
\end{frame}
8282

8383
\begin{frame}[fragile]
84-
\frametitlecpp[98]{Copy constructor}
84+
\frametitlecpp[11]{Copy constructor}
8585
\begin{block}{Concept}
8686
\begin{itemize}
8787
\item special constructor called for replicating an object
@@ -137,7 +137,7 @@
137137
\end{itemize}
138138
\end{block}
139139
\begin{cppcode}
140-
void print( const Vector & v )
140+
void print(const Vector & v)
141141
std::cout<<"printing v elements...\n";
142142
}
143143

@@ -219,15 +219,17 @@
219219
\begin{itemize}
220220
\item avoid having to re-declare parent's constructors
221221
\item by stating that we inherit all parent constructors
222+
\item derived class can add more constructors
222223
\end{itemize}
223224
\end{block}
224225
\begin{exampleblock}{Practically}
225226
\begin{cppcode}
226227
struct BaseClass {
227-
BaseClass(int value);
228+
BaseClass(int a);
228229
};
229230
struct DerivedClass : BaseClass {
230231
using BaseClass::BaseClass;
232+
DerivedClass(int a, int b);
231233
};
232234
DerivedClass a{5};
233235
\end{cppcode}

talk/objectorientation/inheritance.tex

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@
5151

5252
\begin{frame}[fragile]
5353
\frametitlecpp[98]{Managing access to class members}
54-
\begin{block}{{\it public} \color{white} / {\it private} keywords}
54+
\begin{block}{\texttt{public} / \texttt{private} keywords}
5555
\begin{description}
56-
\item[private] allows access only within the class
57-
\item[public] allows access from anywhere
56+
\item[\texttt{private}] allows access only within the class
57+
\item[\texttt{public}] allows access from anywhere
5858
\end{description}
5959
\begin{itemize}
60-
\item The default for \texttt{class} is {\it private}
61-
\item A \texttt{struct} is just a \texttt{class} that defaults to {\it public} access
60+
\item The default for \texttt{class} is \cppinline{private}
61+
\item A \cppinline{struct} is just a class that defaults to \cppinline{public} access
6262
\end{itemize}
6363
\end{block}
6464
\pause
@@ -90,7 +90,7 @@
9090

9191
\begin{frame}[fragile]
9292
\frametitlecpp[98]{Managing access to class members(2)}
93-
\begin{block}{Solution is {\it protected} keyword}
93+
\begin{block}{Solution is \texttt{protected} keyword}
9494
Gives access to classes inheriting from base class
9595
\end{block}
9696
\begin{multicols}{2}
@@ -125,10 +125,10 @@
125125
It influences the privacy of inherited members for external code.\\
126126
The code of the class itself is not affected
127127
\begin{description}
128-
\item[public] privacy of inherited members remains unchanged
129-
\item[protected] inherited public members are seen as protected
130-
\item[private] all inherited members are seen as private \\
131-
this is the default for \texttt{class} if nothing is specified
128+
\item[\texttt{public}] privacy of inherited members remains unchanged
129+
\item[\texttt{protected}] inherited public members are seen as protected
130+
\item[\texttt{private}] all inherited members are seen as private \\
131+
this is the default for classes if nothing is specified
132132
\end{description}
133133
\end{block}
134134
\pause
@@ -137,7 +137,7 @@
137137
\item only public members of public inheritance are accessible
138138
\end{itemize}
139139
\end{block}
140-
\begin{block}{Net result for grand child code}
140+
\begin{block}{Net result for code in derived classes}
141141
\begin{itemize}
142142
\item only public and protected members of public and protected parents are accessible
143143
\end{itemize}

talk/objectorientation/objectsclasses.tex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
\begin{itemize}
9595
\item usually in .cpp, outside of class declaration
9696
\item using the class name as ``namespace''
97-
\item when reference/pointer to the object is needed, use \cppinline{this} keyword
9897
\end{itemize}
9998
\end{block}
10099
\begin{cppcode}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy