Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Programming course
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
courses
Programming course
Commits
6ee29d0e
Commit
6ee29d0e
authored
7 years ago
by
wgallard
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of git.lumc.nl:courses/programming-course
parents
7e9af821
239762f2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
oop/oop.pdf
+0
-0
0 additions, 0 deletions
oop/oop.pdf
oop/oop.tex
+20
-10
20 additions, 10 deletions
oop/oop.tex
with
20 additions
and
10 deletions
oop/oop.pdf
+
0
−
0
View file @
6ee29d0e
No preview for this file type
This diff is collapsed.
Click to expand it.
oop/oop.tex
+
20
−
10
View file @
6ee29d0e
...
...
@@ -45,7 +45,7 @@
\begin{minted}
{
python
}
vectors
_
x = [0, 1, 2]
vectors
_
y = [0, 1, 1]
>>> (vectors
_
x[2], vectors
_
y[
1
])
>>> (vectors
_
x[2], vectors
_
y[
2
])
(2, 1)
\end{minted}
...
...
@@ -89,7 +89,7 @@ interaction.
\item
\mintinline
{
python
}{
42
}
is an instance of type
\mintinline
{
python
}{
int
}
;
\item
\mintinline
{
python
}{
'Hello World!'
}
is an instance of type
\mintinline
{
python
}{
str
ing
}
.
\mintinline
{
python
}{
str
}
.
\end{itemize}
\end{itemize}
\end{frame}
...
...
@@ -161,15 +161,21 @@ Data and procedures (functions) that ``belong'' to the class:
\begin{itemize}
\item
\textcolor
{
pms280
_
compl
}{
Data
}
attributes: the objects that make up
the class;
the class:
\begin{itemize}
\item
a 2d vector is made up of two numbers (
\mintinline
{
python
}{
x
}
and
\mintinline
{
python
}{
y
}
).
\item
\textcolor
{
pms280
_
compl
}{
Methods
}
(procedures);
\end{itemize}
\item
\textcolor
{
pms280
_
compl
}{
Methods
}
(procedures):
\begin{itemize}
\item
functions that
\emph
{
only
}
work with this class;
\item
how to interact with the object;
\item
e.g., calculate the length of a vector.
\end{itemize}
\end{itemize}
\bigskip
\mintinline
{
python
}{
self
}
is the current instance of a class.
...
...
@@ -198,7 +204,7 @@ instance;
\end{itemize}
\end{frame}
\begin{frame}
[fragile]
{
Hiding information --- separation of concern
}
\begin{frame}
[fragile]
{
Hiding information --- separation of concern
s
}
\begin{itemize}
\item
Sometimes we would like to
\textcolor
{
pms280
_
compl
}{
hide
}
attributes to the outside world, i.e., only usable inside the class.
...
...
@@ -210,13 +216,13 @@ class Vector(object):
def
__
init
__
(self, x=0, y=0):
self.x = x
self.y = y
self.
_
secret = 42
self.
_
secret = 42
# this is allowed
\end{minted}
\item
we agree not to access this attribute directly:
\begin{minted}
{
python
}
>>> v1 = Vector(1, 2)
>>> print v1.
_
secret # this is forbidden
>>> print v1.
_
secret
# this is forbidden
\end{minted}
\end{itemize}
...
...
@@ -290,8 +296,11 @@ class Vector(object):
\begin{minted}
{
python
}
>>> v1 = Vector(4, 3)
>>> print type(v1)
<class '
__
main
__
.Vector'>
\end{minted}
%% start minted fix
\vspace
{
-.08cm
}
\mintinline
{
python
}{
<class
}
\mintinline
{
python
}{
'
__
main
__
.Vector'>
}
%% end minted fix
\item
that also works for the class:
\begin{minted}
{
python
}
...
...
@@ -396,7 +405,7 @@ containing two integers: \mintinline{python}{numerator} and
\mintinline
{
python
}{
denominator
}
.
\begin{itemize}
\item
add, subtract;
\item
add, subtract
, e.g.,
$
\frac
{
1
}{
2
}
+
\frac
{
2
}{
3
}
=
\frac
{
7
}{
6
}$
;
\item
print representation, convert to
\mintinline
{
python
}{
float
}
;
\item
invert a fraction;
\item
$
\ldots
$
...
...
@@ -404,7 +413,8 @@ containing two integers: \mintinline{python}{numerator} and
\bigskip
see:
\path
{
https://github.com/lumc-python/oop
}
see:
\path
{
https://github.com/lumc-python/oop
}
\\
or go directly to:
\textcolor
{
pms280
_
compl
}{
\path
{
https://classroom.github.com/a/8BnbL9fD
}}
\end{frame}
\end{document}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment