-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoop.tex
More file actions
1104 lines (928 loc) · 39.8 KB
/
oop.tex
File metadata and controls
1104 lines (928 loc) · 39.8 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MUW Presentation
% LaTeX Template
% Version 1.0 (27/12/2016)
%
% License:
% CC BY-NC-SA 4.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
% Created by:
% Nicolas Ballarini, CeMSIIS, Medical University of Vienna
% nicoballarini@gmail.com
% http://statistics.msi.meduniwien.ac.at/
%
% Customized for UAH by:
% David F. Barrero, Departamento de Automática, UAH
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass[10pt,compress]{beamer} % Change 10pt to make fonts of a different size
\mode<presentation>
\usepackage[spanish]{babel}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage{xstring}
\usepackage{listings}
\usepackage{multicol}
\usepackage{standalone}
\usepackage{tikz}
\usepackage{tikz-uml}
\usetikzlibrary{matrix,chains,positioning,decorations.pathreplacing,arrows,shapes}
\usepackage{minted} % Soporte para resaltado de sintaxis chula
\setminted{fontsize=\footnotesize,breaklines,linenos,highlightcolor=grisUAH}
\newcommand{\python}[2][\footnotesize]{\mintinline[fontsize=#1]{python}{#2}}
\usetheme{UAH}
\usecolortheme{UAH}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{caption}[numbered]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Presentation Info
\title[OOP in Python]{Object-Oriented Programming in Python}
\author{\asignatura\\\carrera}
\institute{}
\date{Departamento de Automática}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Descomentar para habilitar barra de navegación superior
\setNavigation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Configuración de logotipos en portada
%% Opacidad de los logotipos
\newcommand{\opacidad}{1}
%% Descomentar para habilitar logotipo en pié de página de portada
%\renewcommand{\logoUno}{Images/isg.png}
%% Descomentar para habilitar logotipo en pié de página de portada
%\renewcommand{\logoDos}{Images/CCLogo.png}
%% Descomentar para habilitar logotipo en pié de página de portada
%\renewcommand{\logoTres}{Images/ALogo.png}
%% Descomentar para habilitar logotipo en pié de página de portada
%\renewcommand{\logoCuatro}{Images/ELogo.png}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% FOOTLINE
%% Comment/Uncomment the following blocks to modify the footline
%% content in the body slides.
%% Option A: Title and institute
\footlineA
%% Option B: Author and institute
%\footlineB
%% Option C: Title, Author and institute
%\footlineC
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Use this block for a blue title slide with modified footline
{\titlepageBlue
\begin{frame}
\titlepage
\end{frame}
}
\institute{\asignatura}
\begin{frame}[plain]{}
\begin{block}{Objectives}
\begin{enumerate}
\item Introduce basic programming concepts
\item Understand the main characteristics of Object-Oriented Programming (OOP)
\item Use Python to implement class hierarchies
\item Use class libraries: Arcade
\end{enumerate}
\end{block}
\end{frame}
{
\disableNavigation{white}
\begin{frame}[shrink]{Table of Contents}
\frametitle{Table of Contents}
\begin{multicols}{2}
\tableofcontents
\end{multicols}
% You might wish to add the option [pausesections]
\end{frame}
}
\section[Programming paradigms]{Programming paradigms}
\subsection[Understanding concepts]{Understanding concepts}
\begin{frame}{Understanding concepts}{Differentiate between \ldots}
\begin{block}{Programming}
Set of techniques that allow the development of programs using a programming language.
\end{block}
\begin{block}{Programming language}
Set of rules and instructions based on a familiar syntax and later translated into machine language which allow the elaboration of a program to solve a problem. \end{block}
\begin{block}{Paradigm}
Set of rules, patterns and styles of programming that are used by programming languages.
% Conjunto de estandares, teorias y metodos para representar un modo de organizar el pensamiento. % Forma de entender la realidad.
\end{block}
\end{frame}
\subsection[Programming paradigms types]{Programming paradigms types}
\begin{frame}{Programming paradigms types (I)}{}
\begin{block}{Declarative programming}
Describe \alert{what} is used to calculate through conditions, propositions, statements, etc., but does not specify \alert{how}.
\end{block}
\begin{itemize}
\item \textbf{Logic}: follows the first order predicate logic in order to formalize facts of the real world. \textit{(Prolog)}
\begin{itemize}
\item Example: \textit{Anne's father is Raul, Raul's mother is Agnes. Who is Ana's grandmother}
\end{itemize}
\item \textbf{Functional}: it is based on the evaluation of functions (like maths) recursively (\textit{Lisp y Haskell}).
\begin{itemize}
\item Example: \textit{the factorial from 0 and 1 is 1 and n is the factorial from n * factorial (n-1). What is the factorial from 3?}
\end{itemize}
\end{itemize}
\end{frame}
\begin{frame}{Programming paradigms types (II)}
\begin{block}{Imperative programming}
Describes, by a set of instructions that change the \alert{program state}, \alert{how} the task should be implemented.
\end{block}
\begin{itemize}
%\item \textbf{Procedural}: organizes the program using collections of subroutines related by means of invocations (\textit{C, Python}).
%\begin{itemize}
% \item Example: \textit{The cooking process consists of 20 lines of code. When it is used, it only calls the function (1 line).}
%\end{itemize}
\item \textbf{Structural}: is based on nesting, loops, conditionals and subroutines. \textit{(C, Pascal, Python)}.
\begin{itemize}
\item Example: \textit{reviewing products of a shopping list and add the item X to the shopping if it is available.}
\end{itemize}
\item \textbf{Object-Oriented Programming}: is based on objects and classes \textit{(C++, Java, Python)}
\end{itemize}
\bigskip
\textit{Arcade supports both paradigms}\\
\textit{\alert{There are many other paradigms such as Event-Driven programming, Concurrent, Reactive, Generic, etc.}}
\end{frame}
%\begin{frame}{Programming paradigms types (III)}{}
% \begin{block}{Object-Oriented Programming}
% Evolves from imperative programming. It is based on \alert{objects} that allow express the \alert{characteristics} and \alert{behavior} in a closer way to real life.
% \end{block}
% \begin{itemize}
% \item \textbf{Main characteristics}: abstraction, encapsulation, polymorphism, inheritance, modularity, etc.
% \item Example: \textit{a car has a set of properties (color, fuel type, model) and a functionality (speed up, shift gears, braking).}
% \end{itemize}
%\textit{\alert{There are many other paradigms such as Event-Driven programming, Concurrent, Reactive, Generic, etc.}}
%\end{frame}
%\begin{frame}{Programming paradigms types (IV)}{Classification}
%\input{figs/paradigmas.tex}
% \includegraphics[scale=0.4]{figs/paradigmas}
%\caption{http://www.computer.org/csdl/mags/it/2011/05/mit2011050030-abs.html}
% \centering Python supports the three major paradigms, although it stands out for the OOP
%\end{frame}
\begin{frame}{Programming paradigms types (IV)}{Classification}
\centering
\begin{tikzpicture}
\tikzstyle{level 1}=[level distance=2cm]
\tikzstyle{level 2}=[level distance=5cm]
\tikzstyle{level 1}=[sibling distance=5cm]
\tikzstyle{level 2}=[sibling distance=2cm]
\node[rectangle,draw] {PARADIGMS}
child {node[rectangle,draw] {Declarative}
child {node (logic) {Logic}}
child {node (functional) {Functional}}
}
child {node[rectangle,draw] {Imperative}
child {node (structured) {Structured}}
child {node (oop) {OOP}}
}
;
\node[below of=functional] {\textit{Lisp, Haskell, R}};
\node[below of=logic] {\textit{Prolog}};
\node[below of=structured] {\textit{C, Pascal, shell}};
\node[below of=oop] {\textit{Java, C++, Python}};
\end{tikzpicture}
\bigskip
\centering Python supports the three major paradigms, although it stands out for the OOP
\end{frame}
\section[Object-Oriented Programming]{Object-Oriented Programming}
\subsection{Objectives}
\begin{frame}{Object-Oriented Programming}{Objectives}
\begin{itemize}
\item \textbf{Reusability}: Ability of software elements to serve for the construction of many different applications.
\item \textbf{Extensibility}: Ease of adapting software products to specification changes.
\item \textbf{Maintainability}: Amount of effort necessary for a product to maintain its normal functionality.
\item \textbf{Usability}: Ease of using the tool.
% \item \textbf{Robustness}: Ability of software systems to react appropriately to exceptional conditions.
% \item \textbf{Correction}: Ability of software products to perform their tasks accurately, as defined in their specifications.
\end{itemize}
\end{frame}
\subsection{Basic concepts}
\begin{frame}{Object-Oriented Programming}{Concepts (I)}
\begin{block}{Class}
Generic entity that groups attributes and functions
\end{block}
\begin{columns}[t]
\column{.5\textwidth}
\begin{block}{Atribute}
Individual characteristics that determine the qualities of an object
\end{block}
\begin{figure}
\includegraphics[width=0.8\linewidth]{figs/clase}
\end{figure}
\column{.5\textwidth}
\begin{block}{Method}
Function responsible for performing operations
\end{block}
\begin{figure}
\includegraphics[width=0.8\linewidth]{figs/metodo}
\end{figure}
\end{columns}
\end{frame}
\begin{frame}{Object-Oriented Programming}{Concepts (IV)}
\vfill\begin{block}{Object or instance}
Specific representation of a class, namely, a class member with their corresponding attributes.
\end{block}
\begin{figure}
\includegraphics[scale=0.5]{figs/instancia}\hfill
\includegraphics[width=0.5\linewidth]{figs/laika}
\end{figure}
\end{frame}
\begin{frame}[plain]{Object-Oriented Programming}{Concepts (V)}
\begin{center}
\includegraphics[width=0.6\linewidth]{figs/pacman}\\
\smallskip
\tiny{\href{http://blog.sklambert.com/introduction-to-oop-for-game-development/}{(Source)}}
\end{center}
\end{frame}
\begin{frame}[fragile]{Object-Oriented Programming}{Concepts (VI)}
\centering {Two operations on classes}
\begin{columns}
\column{.50\textwidth}
\begin{block}{Instantiation}
Creates a new object\\
Standard functional notation\\
\bigskip
\centering{\texttt{x = MyClass()}}\\
\end{block}
\begin{exampleblock}{Example}
\begin{verbatim}
>>> snoopy = Dog()
>>> laika = Dog("Laika")
\end{verbatim}
\end{exampleblock}
\column{.50\textwidth}
\begin{block}{Attribute references}
Accesses an attribute value\\
Standard dot syntax\\
\bigskip
\centering{\texttt{obj.name}}\\
\end{block}
\begin{exampleblock}{Example}
\begin{verbatim}
>>> snoopy.name = "Snoopy"
>>> print(snoopy.name)
>>> name = snoopy.name
\end{verbatim}
\end{exampleblock}
\end{columns}
\end{frame}
\subsection{Constructors}
\begin{frame}{Object-Oriented Programming}{Constructors (I)}
\begin{block}{Constructor}
Method called when an object is created. It allows the initialization of attributes.
\end{block}
\begin{figure}
\includegraphics[scale=0.5]{figs/constructor}
\end{figure}
\end{frame}
\begin{frame}{Concepts of OOP}{Constructors (II)}
Instantiation creates empty objects
\begin{itemize}
\item We usually need to initialize attributes
\item Initialization operations
\end{itemize}
\alert{Constructor}: Method called when an object is created
\begin{itemize}
\item In Python, it is the \texttt{\_\_init\_\_()}
\item A constructor can get arguments
\end{itemize}
\end{frame}
%\begin{frame}{Object-Oriented Programming}{Constructors (III)}
% \vspace{-0.3cm}
% \begin{exampleblock}{}
% \vspace{-0.3cm}
% \lstinputlisting{code/Time3.py}
% \end{exampleblock}
%\end{frame}
%\begin{frame}{Object-Oriented Programming}{Synthesizing OOP terminology}
% \begin{itemize}
% \item \small{Software objects mimics physical objects.} % un individuo o ejemplar de una clase
% \begin{itemize}
% \item \footnotesize{An object contains \textit{attributes} (state) and a \textit{behaviour}}. % behavior u operaciones
% \item \footnotesize{Example: A dog has a name (state) and may be a bit (behaviour).}
% \end{itemize}
% \item Objects are grouped into classes.
% \item \small{A \alert{class} is a set of objects with common characteristics and behaviour.}
% \item \small{An \alert{object} is called an \alert{Instance} of a class.}
% It can also be described as a pattern or template that is used to create objects.
% \item \textit{Members} of a class:
% \begin{itemize}
% \item \footnotesize{\alert{Properties}: Data describing an object.}
% \item \footnotesize{\alert{Methods}: What an object can do.}%Something that can be done to object. % o procedimiento perteneciente a un objeto.
% modo en que se comunican los objetos entre síi.
% \end{itemize}
% \item Property = Member, attribute, variable, etc.
% \end{itemize}
%\end{frame}
\begin{frame}[plain]%{Object-Oriented Programming}{Code example}
\vspace{-0.3cm}
\begin{columns}
\column{.7\textwidth}
\begin{exampleblock}{dog.py}
%\vspace{-0.2cm}
\inputminted[fontsize=\scriptsize]{python}{code/dogs.py}
%\lstinputlisting[numbers=left,basicstyle=\ttfamily\scriptsize]{code/dogs.py}
\end{exampleblock}
\column{.3\textwidth}
\begin{exampleblock}{Output}
\vspace{-0.2cm}
\lstinputlisting[basicstyle=\ttfamily\scriptsize]{code/dogs-output.txt}
\end{exampleblock}
\href{https://gist.github.com/dfbarrero/9b30c749986885373c8c250b3901ec9d}{(Source code)}
\bigskip
\pause
\centering UML class diagram
\begin{tikzpicture}
\umlclass{Dog}
{+ name : str\\ + age : int}
{+ bit () : void\\ +describe () : void}
\end{tikzpicture}
\end{columns}
\end{frame}
\subsection{OO game example}
\begin{frame}[plain]{Object-Oriented Programming}{OO game example}
\begin{center}
\centering \includegraphics[width=0.8\linewidth]{figs/gameObjects}\\
\smallskip
\tiny{\href{http://blog.nuclex-games.com/2010/01/game-architecture-day-2/}{(Source)}}
\end{center}
\end{frame}
\section{Inheritance}
\subsection{Definition}
\begin{frame}{Inheritance}{Definition}
\vspace{-0.2cm}
\begin{block}{Inheritance}
Mechanism of \alert{reusing} code in OOP. Consists of generating child classes from other existing (\alert{super-class}) allowing the use and adaptation of the attributes and methods of the parent class to the child class
\end{block}
\bigskip
A subclass inherits all the attributes and methods from its superclass
\begin{itemize}
\item {\textit{Superclass}: ``Father'' of a class}
\item {\textit{Subclass}: ``Child'' of a class}
\end{itemize}
\end{frame}
\subsection{Examples}
\begin{frame}{Inheritance}{Examples of simple inheritance (I)}
\begin{tikzpicture}
\umlclass{Dog}
{+ name : str\\ + age : int}
%{+ name : str\\ + age : int\\ + fleas : int}
{+ bit() : void\\ + describe() : void}
\umlclass[x=3]{Cat}
{+ name : str\\ + age : int}
{+ scratch() : void\\ + describe() : void}
\end{tikzpicture}
\end{frame}
\begin{frame}{Inheritance}{Examples of simple inheritance (II)}
\begin{tikzpicture}
\umlclass{Animal}
{+ name : str\\ + age : int}
{+ describe() : void}
\umlclass[x=-2, y=-3]{Dog}
%{+ fleas : int}
{}
{+ bit() : void}
\umlclass[x=2, y=-3]{Cat}
{}
{+ scratch() : void}
\umlinherit[geometry=|-]{Dog}{Animal}
\umlinherit[geometry=|-]{Cat}{Animal}
\end{tikzpicture}
\end{frame}
\begin{frame}[plain]%{Characteristics}{Examples of simple inheritance (III)}
\begin{columns}
\column{.7\textwidth}
\begin{exampleblock}{dog.py}
%\vspace{-0.2cm}
\inputminted[fontsize=\scriptsize, highlightlines={10,14}]{python}{code/animals.py}
\end{exampleblock}
\end{columns}
\centering \small \href{https://gist.github.com/dfbarrero/9b30c749986885373c8c250b3901ec9d}{(Source code)}
\end{frame}
\begin{frame}{Inheritance}{Examples of simple inheritance (III)}
\textit{Class hierarchy}: A set of classes related by inheritance \\
\begin{figure}
\includegraphics[scale=0.33]{figs/herencia1}
\caption{{\scriptsize Example of simple Inheritance in OOP. Obtained from: \url{http://android.scenebeta.com}}}
\end{figure}
\end{frame}
\begin{frame}{Inheritance}{Examples of simple inheritance (IV)}
\begin{center}
\centering \includegraphics[width=0.5\linewidth]{figs/class-diagram.png}\\
\smallskip
\tiny{\href{https://amysgamedevelopmentblog.wordpress.com/2016/10/17/requirements-for-a-game-why-is-planning-important/}{(Source)}}
\end{center}
\end{frame}
\begin{frame}[plain]{Inheritance}{Examples of simple inheritance (V)}
\begin{columns}
\column{.3\textwidth}
\begin{tikzpicture}
\umlclass{Weapon}
{- name : str\\ - damage : int\\- sprite : Image}
{+ draw() : void\\ + use(): void}
\umlclass[x=-3, y=-3]{Bow}
{+ arrows : int}
{+ use() : void}
\umlclass[x=0, y=-3]{Sword}
{+ resistance : int}
{+ use() : void\\+ charge() : void}
\umlclass[x=3, y=-3]{Wand}
{+ mana : int}
{+ use() : void\\+ castSpell(str)}
\umlclass[x=5, y=1]{Character}
{+ name : str\\ + life : int\\+ skill : int\\+ weapon : Weapon}
{+ move(x,y) : void\\+ attack(Character) : void\\ + combat(Character) : void}
\umlinherit[geometry=|-]{Bow}{Weapon}
\umlinherit[geometry=--]{Sword}{Weapon}
\umlinherit[geometry=|-]{Wand}{Weapon}
\umlaggreg[geometry=--, mult1=1, mult2=*]{Character}{Weapon}
\end{tikzpicture}
\column{.7\textwidth}
\end{columns}
\end{frame}
\subsection{Types of inheritance}
\begin{frame}{Inheritance}{Types of inheritance (I)}
\begin{block}{Types of inheritance}
\begin{itemize}
\item If the child class inherits from a single class is called \alert{single inheritance}.
\item if it inherits from more classes is \alert{multiple inheritance}.
\end{itemize}
\end{block}
\medskip
\textit{Python allows both; simple and multiple inheritance.}
\end{frame}
\begin{frame}{Inheritance}{Types of inheritance (II)}
\begin{figure}
\includegraphics[scale=0.5]{figs/herencia2}
\caption{{\scriptsize Example of multiple Inheritance in OOP. Obtained from: \url{http://www.avizora.com}}}
\end{figure}
\end{frame}
\section{Concepts of OOP}
\subsection{Polymorphism}
\begin{frame}{Concepts of OOP}{Polymorphism (I)}
\begin{columns}
\column{.4\textwidth}
\begin{block}{Polymorphism}
Mechanism of object-oriented programming that allows to invoke a method whose implementation will depend on the object that does it.
\end{block}
% TIPOS DE POLIMORFISMO
% \begin{itemize}
% \item \justifying\textbf{Polimorfismo de sobrecarga}: mismo nombre y tipos de datos en diferentes clases.
% \item \justifying\textbf{Polimorfismo paramétrico}: mismo nombre diferentes tipos de datos.
% \item \justifying\textbf{Polimorfismo de subtipado}: Permite invocar un método de una clase especializada a partir de la clase padre.
% \end{itemize}
% \begin{figure}
\column{.6\textwidth}
\begin{tikzpicture}
\umlclass{Animal}
{+ name : str\\ + age : int}
{+ describe() : void\\+ attack() : void}
\umlclass[x=-2, y=-3]{Dog}
%{+ fleas : int}
{}
{+ attack() : void}
\umlclass[x=2, y=-3]{Cat}
{}
{+ attack() : void}
\umlinherit[geometry=|-]{Dog}{Animal}
\umlinherit[geometry=|-]{Cat}{Animal}
\end{tikzpicture}
\end{columns}
%\vspace{-0.2cm}
% \includegraphics[width=4.6cm]{figs/polimorfismo1}
% \vspace{-0.2cm}
% \caption{\scriptsize{Example of polymorphism. Obtained from: \url{http://virtual.uaeh.edu.mx}}}
% \end{figure}
\end{frame}
%\begin{frame}{Characteristics}{Polymorphism (II)}
% \begin{figure}
% \includegraphics[scale=0.57]{figs/polimorfismo2}
% \vspace{-0.1cm}
% \caption{{\scriptsize Example of polymorphism. Obtained from: \url{http://datateca.unad.edu.co}}}
% \end{figure}
%\end{frame}
\begin{frame}[plain]%{Characteristics}{Examples of simple inheritance (III)}
\begin{columns}
\column{.8\textwidth}
\begin{exampleblock}{}
\inputminted[fontsize=\scriptsize, highlightlines={28,29}]{python}{code/animalsPolymorphism.py}
\end{exampleblock}
\end{columns}
\centering \href{https://gist.github.com/dfbarrero/0b401926b92a5e36ad08a3eae5fbd16c}{(Source code)}
\end{frame}
%\subsection{Abstraction}
%\begin{frame}{Concepts of OOP}{Abstraction}
% \begin{block}{Abstraction}
% Mechanism that allows the isolation of the not relevant information to a level of knowledge.
% \end{block}
% \begin{itemize}
% \item \textit{A driver does not need to know how the carburetor works.}
% \item \textit{To talk on the phone does not need to know how the voice is transferred.}
% \item \textit{To use a computer do not need to know the internal composition of their materials}.
%
%% \vfill\item \textit{\alert{En Python no existen de manera nativa las clases abstractas pero si mediante el módulo ABC \cite{PythonTeam}.}}
% \end{itemize}
%\end{frame}
\subsection{Encapsulation}
\begin{frame}{Concepts of OOP}{Encapsulation (I)}
\begin{block}{Encapsulation}
Mechanism use to provide an access level to methods and attributes for avoiding unexpected state changes
\end{block}
\begin{figure}
\includegraphics[scale=0.35]{figs/abstraccion2}
\scriptsize \href{http://www.onlinebuff.com}{(Source)}
\end{figure}
\end{frame}
\begin{frame}{Concepts of OOP}{Encapsulation (II)}
The most common access levels are:
\begin{itemize}
\item \textbf{public}: visible for everyone , default in Python
\item \textbf{private}: visible for the class
\begin{itemize}
\item By \textit{convenion} in Python, starts with one underscore
\item `Superprivate' starts with a double underscore and does not end in the same manner
\end{itemize}
\item \textbf{protected}: visible for the creator class and its descendents \textit{[it does not exist in Python]}
\end{itemize}
\bigskip
``Getters'' and ``setters'' methods to control the access to attributes
\end{frame}
\begin{frame}[plain]%{Characteristics}{Examples of simple inheritance (III)}
\begin{columns}
\column{.7\textwidth}
\begin{exampleblock}{}
\inputminted[fontsize=\scriptsize]{python}{code/access.py}
\end{exampleblock}
\end{columns}
\end{frame}
\subsection{Encapsulation: The ``pythonic'' way}
\begin{frame}{Concepts of OOP}{Encapsulation: The ``pythonic'' way (I)}
Getters and setters come with some drawbacks
\begin{itemize}
\item Verbose and repetitive code
\item Linked to the API
\end{itemize}
A more pythonic way to define getters and setters is using \alert{properties}
\begin{itemize}
\item It is a \alert{decorator} that transforms methods into getters or setters
\item[] \textbf{$@$property}: Getter
\item[] \textbf{$@$object.setter}: Setter
\item Neverless, getters and setters are still used in Python under certain circumstances
\end{itemize}
Better with an example ...
\end{frame}
\begin{frame}{Concepts of OOP}{Encapsulation: The ``pythonic'' way (II)}
\begin{columns}
\column{.6\textwidth}
\begin{exampleblock}{}
\inputminted[fontsize=\scriptsize, highlightlines={5,9}]{python}{code/access-pythonic.py}
\end{exampleblock}
\end{columns}
\end{frame}
%\section{Classes in Python}
% \subsection{Syntax}
%Sintaxis básica
%\begin{frame}{Nomeclatura de Python}{Sintaxis(I)}
% \begin{itemize}
% \item \justifying \textbf{Impresión por pantalla}: \texttt{print}. Por defecto solo admite la codificación inglesa (sin tildes ni ñ).
% \begin{itemize}
% \item Para que las admita, se escribe antes: \# -*- coding: utf-8 -*-
% \item Para imprimir texto se escribe entre comillas dobles.
% \end{itemize}
% \item \justifying\textbf{Indentación}: Python utiliza espacios o tabulaciones para definir los distintos niveles en el código, por lo tanto si un fragmento se encuentra a la derecha del superior indica que está contenido en la instrucción anterior.
% \item \justifying \textbf{Comentarios}: Comienzan con \#.
% \end{itemize}
% \begin{columns}
% \column{0.8\textwidth}
% \begin{block}{holaMundo.py}
% \vspace{-0.3cm}
% \lstinputlisting[basicstyle=\ttfamily\scriptsize]{code/holaMundo.py} % contar elementos
% \end{block}
% \end{columns}
%\end{frame}
%\begin{frame}{Nomeclatura de Python}{Sintaxis(II)}
% \begin{itemize}
% \item \justifying \textbf{Asignación}: Se expresa mediante un igual.
% \item \justifying \textbf{Atributo}: sustantivo expresado con minúscula.
% \item \justifying \textbf{Condiciones}: \texttt{if/elif/else + condición:}. Permiten expresar que hacer si se satisface o no una condición. Para expresar una condición de igualdad se utiliza \texttt{==}
% \begin{columns}
% \column{0.8\textwidth}
% \begin{block}{semaforo.py}
% \vspace{-0.3cm}
% \lstinputlisting[basicstyle=\ttfamily\scriptsize]{code/semaforo.py} % contar elementos
% \end{block}
% \end{columns}
% \end{itemize}
%\end{frame}
%\begin{frame}{Nomeclatura de Python}{Sintaxis(III)}
% \begin{itemize}
% \item \justifying \textbf{Estructuras iterativas}: \texttt{while/for + condición:}. Permiten expresar el mismo código mientras se cumpla la condición.
% \end{itemize}
% \begin{columns}
% \column{0.8\textwidth}
% \begin{block}{provincias.py}
% \vspace{-0.3cm}
% \lstinputlisting[basicstyle=\ttfamily\scriptsize]{code/provincias.py} % contar elementos
% \end{block}
% \end{columns}
%\end{frame}
%\begin{frame}{Classes in Python}{Syntax (I)}
%\vspace{-0.2cm}
%\begin{itemize}
% \item \small{\textbf{Class}: Start with the word \alert{class} followed by class name written in \alert{capital letter} and a colon [Substantives].}
% \item \small{\textbf{Attributes}: A lowercase noun.}
% \begin{itemize}
% \item \footnotesize{There is no need to declare attributes.}
% \end{itemize}
% \item \small{\textbf{Inherited class}: Similar to a class but the class name followed by the class father in brackets.}
% \item \small{\textbf{Instance}: Object in lower case followed by the class assignment.}
% \vspace{-0.2cm}
% \begin{columns}
% \column{0.8\textwidth}
% \begin{block}{\small{coche.py}}
% \vspace{-0.3cm}
% \lstinputlisting[basicstyle=\ttfamily\scriptsize]{code/coche.py} % contar elementos
% \vspace{-0.2cm}
% \end{block}
% \end{columns}
%\end{itemize}
%\end{frame}
%\begin{frame}{Classes in Python}{Syntax (II)}
%\begin{itemize}
% \item \textbf{Method}: Start with the word \alert{def}, and later the method, a verb, in lower case is written. Next, the parameter in brackets and a colon (\texttt{print\_name()}).
% \begin{itemize}
% \item Methods receive automatically a reference to the object (usually named \texttt{self}).
% \end{itemize}
% \item \textbf{Constructor}: Method whose name is \texttt{\_\_init\_\_()}, the first attribute is \texttt{self} and then the class attributes are written.
% \item \textbf{main}: Method defined with \texttt{def main():}. In it, the wished commands are specified and after it, an exit condition is created. The \texttt{sys} module is required to be imported at the beginning.
% \item All methods and attributes are public.
% \begin{itemize}
% \item By convention, private members begin with double underscore (\texttt{\_\_varName}, \texttt{\_\_method\_name()})
% \end{itemize}
%\end{itemize}
%\end{frame}
%\begin{frame}{Classes in Python}{Syntax (III). Example 1}
% \begin{columns}
% \column{0.8\textwidth}
% \begin{block}{main.py}
% \vspace{-0.3cm}
% \lstinputlisting[basicstyle=\ttfamily\scriptsize]{code/main.py} % contar elementos
% \end{block}
% \end{columns}
%\end{frame}
%\begin{frame}{Classes in Python}{Syntax (IV). Example 2}
%\vspace{-0.2cm}
% \begin{columns}
% \column{0.8\textwidth}
% \begin{block}{bicicleta.py}
% \vspace{-0.3cm}
% \lstinputlisting[basicstyle=\ttfamily\scriptsize]{code/bicicleta.py} % contar elementos
% \vspace{-0.3cm}
% \end{block}
% \end{columns}
%\end{frame}
%\begin{frame}{Classes in Python}{Syntax (V). Example 3}
% \vspace{-0.2cm}
% \begin{block}{Time.py}
% \vspace{-0.3cm}
% \lstinputlisting{code/Time.py}
% \vspace{-0.3cm}
% \end{block}
%\end{frame}
\subsection{More about methods}
\begin{frame}{Concepts of OOP}{Other special methods}
Several special methods, including:
%\begin{block}{}
% \vspace{-0.15cm}
\begin{itemize}
\item \footnotesize{\texttt{\_\_str\_\_(self)} It should return a string with information}
\item \footnotesize{\texttt{\_\_len\_\_(self)} It should return the length or ``size'' of object (number of elements if is a \textit{set} or \textit{queue})}
%\item \footnotesize{\texttt{\_\_add\_\_(self, otro\_obj)} It allows to apply the addition operator (+) to objects of the class in which it is defined.}
%\item \footnotesize{\texttt{\_\_mul\_\_(self, otro\_obj)} It allows to apply the multiplication operator (*) to objects of the class in which it is defined.}
%\item \footnotesize{\texttt{\_\_comp\_\_(self, otro\_obj)} It allows to apply the comparison operators (<, >, <=, >=, ==, !=) to objects of the class in which it is defined. It should return 0 if they are equal, -1 if \texttt {self} is smaller than \texttt{other\_obj} and 1 if \texttt{self} is greater than \texttt{other\_obj}.}
\end{itemize}
% \vspace{-0.2cm}
%\end{block}
\vspace{-0.2cm}
\begin{columns}
\column{.6\textwidth}
\begin{exampleblock}{}
%\vspace{-0.3cm}
\inputminted[fontsize=\scriptsize, highlightlines={13,14}]{python}{code/inventory-len.py}
\vspace{-0.2cm}
\end{exampleblock}
\end{columns}
\end{frame}
\subsection{Overriding methods}
\begin{frame}{Concepts of OOP}{Overriding methods (I)}
Often we need to adapt an inheritanced method: \alert{Overriding}
\begin{columns}
\column{.6\textwidth}
\begin{exampleblock}{Overriding example}
\inputminted{python}{code/Overriding.py}
\end{exampleblock}
\end{columns}
\end{frame}
\begin{frame}{Concepts of OOP}{Overriding methods (II)}
Still possible to get superclass' method with \texttt{super()}
\begin{columns}
\column{.6\textwidth}
\begin{exampleblock}{Overriding example}
\inputminted{python}{code/Overriding2.py}
\end{exampleblock}
\end{columns}
\end{frame}
\section{Arcade}
\begin{frame}[plain]
\begin{exampleblock}{}
\inputminted{python}{code/arcade-1.py}
\end{exampleblock}
\end{frame}
\begin{frame}[plain]
\begin{exampleblock}{}
\inputminted{python}{code/arcade-2.py}
\lstinputlisting[numbers=left]{code/arcade-2.py}
\end{exampleblock}
\end{frame}
\begin{frame}{Arcade}
The \texttt{arcade.Window} class.
\begin{block}{}
% \vspace{-0.15cm}
\begin{itemize}
\item \footnotesize{\texttt{on\_draw()}}. Override this function to add your custom drawing code
\item \footnotesize{\texttt{on\_update(delta\_time: float)}}. Move everything. Perform collision checks. Do all the game logic here
\item[]
\item \footnotesize{\texttt{on\_key\_release(symbol: int, modifiers: int)}}
\item \footnotesize{\texttt{on\_mouse\_release(x: float, y: float, button: int, modifiers: int)}}. Override this function to add mouse button functionality
%\item \footnotesize{\texttt{set\_viewport(left: float, right: float, bottom: float, top: float)}}. Set the coordinates we can see
\end{itemize}
% \vspace{-0.2cm}
\end{block}
Check out \href{https://api.arcade.academy/en/stable/api/window.html\#arcade-window}{(reference documentation)}
\end{frame}
\section{Exercises}
\subsection{Exercise 1: Asteroids}
\begin{frame}{Exercise 1: Asteroids}
\vspace{-0.3cm}
\begin{columns}
\column{.6\textwidth}
\centering \includegraphics[width=\linewidth]{figs/asteroids.png}\\
\tiny{\href{http://gamedevelopment.tutsplus.com/tutorials/quick-tip-intro-to-object-oriented-programming-for-game-development--gamedev-1805}{(Source)}}
\column{.4\textwidth}
\begin{enumerate}
\item Identify the classes in the Asteroids videogame
\item Identify attributes contained in the previous classes
\item Identify methods contained in the previous classes
\end{enumerate}
\end{columns}
\end{frame}
\subsection{Exercise 2: Tetris}
\begin{frame}{Exercise 2: Tetris}
\begin{columns}
\column{.4\textwidth}
\centering \includegraphics[width=\linewidth]{figs/tetris.png}\\
\tiny{\href{http://gamedevelopment.tutsplus.com/tutorials/quick-tip-intro-to-object-oriented-programming-for-game-development--gamedev-1805}{(Source)}}
\column{.4\textwidth}
\begin{enumerate}
\item Identify the classes in the Tetris videogame
\item Identify attributes contained in the previous classes
\item Identify methods contained in the previous classes
\end{enumerate}
\end{columns}
\end{frame}
\subsection{Exercise 3: Pac-Man}
\begin{frame}{Exercise 3: Pac-Man}
\begin{columns}
\column{.5\textwidth}
\centering \includegraphics[width=\linewidth]{figs/pacman2.png}\\
\tiny{\href{http://gamedevelopment.tutsplus.com/tutorials/quick-tip-intro-to-object-oriented-programming-for-game-development--gamedev-1805}{(Source)}}
\column{.5\textwidth}
\begin{enumerate}
\item Identify the classes in the Pac-Man videogame
\item Identify attributes contained in the previous classes
\item Identify methods contained in the previous classes
\end{enumerate}
\end{columns}
\end{frame}
%\begin{frame}{Exercise statement}{\texttt{Animal} class}
% \begin{enumerate}
% \item Create the \texttt{animal} class.
% \item Create the constructor. The class will have the attributes \texttt{tipo} and \texttt{patas}.
% %con las variables tipo de animal y número de patas.
% \item Create the get methods from both attributes which receive like own parameter the animal through \texttt{self} and return respectively the \texttt{tipo} and \texttt{patas}.
% \item Create two instances of animals using the constructor.
% \item Print the attributes of both instances.
% \end{enumerate}
%\end{frame}
%\begin{frame}{Solved exercise}{\texttt{Animal} class}
% \vspace{-0.2cm}
% \begin{columns}
% \column{0.8\textwidth}
% \begin{block}{animales.py}
% \vspace{-0.3cm}
% \lstinputlisting[basicstyle=\ttfamily\scriptsize]{code/animales.py} % contar elementos
% \vspace{-0.3cm}
% \end{block}
% \end{columns}
%\end{frame}
%\begin{frame}{Solved exercise}{\texttt{Animal} class}
% \begin{enumerate}