Skip to content

Commit f2e3c9a

Browse files
committed
module4 added (by Penturion)
1 parent 8dbfe68 commit f2e3c9a

File tree

10 files changed

+249
-0
lines changed

10 files changed

+249
-0
lines changed

module4/abstraction.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!-- .slide: data-background="#111111" -->
2+
3+
# Abstraction
4+
5+
___
6+
7+
## Abstraction
8+
9+
* <!-- .element: class="fragment fade-in" --> Interface
10+
* <!-- .element: class="fragment fade-in" --> The public part of a class
11+
* <!-- .element: class="fragment fade-in" --> Member function - obvious
12+
* <!-- .element: class="fragment fade-in" --> Non-member function
13+
* <!-- .element: class="fragment fade-in" --> Member types
14+
* <!-- .element: class="fragment fade-in" --> Member fields
15+
* <!-- .element: class="fragment fade-in" --> Template parameters
16+
* <!-- .element: class="fragment fade-in" --> Specializations
17+
* <!-- .element: class="fragment fade-in" --> Example: <a href="https://en.cppreference.com/w/cpp/container/vector"><code>std::vector</code> on cppreference.com</a>
18+
* <!-- .element: class="fragment fade-in" --> The private part (implementation) is unknown
19+
* <!-- .element: class="fragment fade-in" --> Object Oriented Design (OOD)
20+
21+
> Make interfaces easy to use correctly and hard to use incorrectly
22+
>
23+
> \-\- Scott Meyers, [Effective C++](https://blog.ycshao.com/2012/11/23/effective-c-item-18-make-interfaces-easy-to-use-correctly-and-hard-to-use-incorrectly/)
24+
<!-- .element: class="fragment fade-in" -->
25+
26+
___
27+
28+
## Bad interface example
29+
30+
```c++
31+
// A date class which is easy to use but also easy to use wrong.
32+
class Date {
33+
public:
34+
Date(int month, int day, int year);
35+
...
36+
};
37+
38+
// Both are ok, but some european programmer may use it wrong,
39+
// because european time format is dd/mm/yyyy instead of mm/dd/yyyy.
40+
Date d(3, 4, 2000);
41+
Date d(4, 3, 2000);
42+
```

module4/agenda.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- .slide: data-background="#111111" -->
2+
3+
# Agenda
4+
5+
* <!-- .element: class="fragment fade-in" --> 4 pillars of objectivity
6+
* <!-- .element: class="fragment fade-in" --> Abstraction
7+
* <!-- .element: class="fragment fade-in" --> Encapsulation
8+
* <!-- .element: class="fragment fade-in" --> Inheritance
9+
* <!-- .element: class="fragment fade-in" --> Polymorphism

module4/cover.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- .slide: data-background="#111111" -->
2+
3+
# Object-oriented C++
4+
5+
<a href="https://coders.school">
6+
<img width="500" data-src="../img/coders_school_logo.png" alt="Coders School" class="plain">
7+
</a>
8+
9+
### Łukasz Ziobroń

module4/encapsulation.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!-- .slide: data-background="#111111" -->
2+
3+
# Encapsulation
4+
5+
___
6+
7+
## Encapsulation
8+
9+
* <!-- .element: class="fragment fade-in" --> Access specifiers
10+
* <!-- .element: class="fragment fade-in" --> <code>public</code> - <code>struct</code> default
11+
* <!-- .element: class="fragment fade-in" --> <code>protected</code>
12+
* <!-- .element: class="fragment fade-in" --> <code>private</code> - <code>class</code> default
13+
* <!-- .element: class="fragment fade-in" --> Setters and getters
14+
* <!-- .element: class="fragment fade-in" --> Unnamed namespaces

module4/exercise_cars.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- .slide: data-background="#111111" -->
2+
3+
# Exercise
4+
5+
___
6+
7+
## Cars
8+
9+
1. <!-- .element: class="fragment fade-in" --> Design proper abstraction (interfaces)
10+
2. <!-- .element: class="fragment fade-in" --> Apply inheritance
11+
3. <!-- .element: class="fragment fade-in" --> Fix encapsulation
12+
4. <!-- .element: class="fragment fade-in" --> Use polymorphism to represent every type of car, using a single pointer
13+
5. <!-- .element: class="fragment fade-in" --> Fix diamond problem
14+
6. <!-- .element: class="fragment fade-in" --> Fix potential memory leaks
15+
7. <!-- .element: class="fragment fade-in" --> Think about the way of keeping engines in cars. Should they be kept by a value, reference or a pointer (what kind of pointer)?
16+
8. <!-- .element: class="fragment fade-in" --> Is this code testable?
17+
18+
### [View task in repo](https://github.com/coders-school/Cars.git)
19+
<!-- .element: class="fragment fade-in" -->

module4/index.html

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
6+
7+
<title>Object-oriented C++</title>
8+
9+
<meta name="description" content="C++11, C++14 and C++17 presentation">
10+
<meta name="author" content="Lukasz Ziobron">
11+
12+
<link rel="stylesheet" href="../css/reset.css">
13+
<link rel="stylesheet" href="../css/reveal.css">
14+
<link rel="stylesheet" href="../css/theme/coders.css" id="theme">
15+
16+
<!-- Theme used for syntax highlighting of code -->
17+
<link rel="stylesheet" href="../lib/css/monokai.css">
18+
19+
<!-- Printing and PDF exports -->
20+
<script>
21+
var link = document.createElement('link');
22+
link.rel = 'stylesheet';
23+
link.type = 'text/css';
24+
link.href = window.location.search.match(/print-pdf/gi) ? 'css/print/pdf.css' : 'css/print/paper.css';
25+
document.getElementsByTagName('head')[0].appendChild(link);
26+
</script>
27+
</head>
28+
<body>
29+
30+
<div class="reveal">
31+
<div class="slides">
32+
<section data-markdown="../md.object_oriented/cover.md" data-separator-vertical="^___"
33+
data-separator-notes="^Note:">
34+
</section>
35+
<section data-markdown="../md.object_oriented/agenda.md" data-separator-vertical="^___"
36+
data-separator-notes="^Note:">
37+
</section>
38+
<section data-markdown="../md.object_oriented/pillars.md" data-separator-vertical="^___"
39+
data-separator-notes="^Note:">
40+
</section>
41+
<section data-markdown="../md.object_oriented/abstraction.md" data-separator-vertical="^___"
42+
data-separator-notes="^Note:">
43+
</section>
44+
<section data-markdown="../md.object_oriented/encapsulation.md" data-separator-vertical="^___"
45+
data-separator-notes="^Note:">
46+
</section>
47+
<section data-markdown="../md.object_oriented/inheritance.md" data-separator-vertical="^___"
48+
data-separator-notes="^Note:">
49+
</section>
50+
<section data-markdown="../md.object_oriented/polymorphism.md" data-separator-vertical="^___"
51+
data-separator-notes="^Note:">
52+
</section>
53+
<section data-markdown="../md.object_oriented/exercise_cars.md" data-separator-vertical="^___"
54+
data-separator-notes="^Note:">
55+
</section>
56+
<section data-markdown="../md.object_oriented/post_work.md" data-separator-vertical="^___"
57+
data-separator-notes="^Note:">
58+
</section>
59+
<section data-markdown data-background="#111111">
60+
<!-- Added ending slide -->
61+
# The End &#128522 !
62+
</section>
63+
</div>
64+
65+
</div>
66+
67+
<script src="../js/reveal.js"></script>
68+
69+
<script>
70+
// More info about config & dependencies:
71+
// - https://github.com/hakimel/reveal.js#configuration
72+
// - https://github.com/hakimel/reveal.js#dependencies
73+
Reveal.initialize({
74+
width: 1200,
75+
height: 750,
76+
slideNumber: true,
77+
hash: true,
78+
pdfSeparateFragments: false,
79+
dependencies: [
80+
{ src: '../plugin/externalcode/externalcode.js', condition: function() { return !!document.querySelector( '[data-code]' ); } },
81+
{ src: '../plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
82+
{ src: '../plugin/markdown/marked.js' },
83+
{ src: '../plugin/markdown/markdown.js' },
84+
{ src: '../plugin/notes/notes.js', async: true }
85+
]
86+
});
87+
</script>
88+
</body>
89+
</html>

module4/inheritance.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!-- .slide: data-background="#111111" -->
2+
3+
# Inheritance
4+
5+
___
6+
7+
## Inheritance
8+
9+
* <!-- .element: class="fragment fade-in" --> Constructors and destructors call order
10+
* <!-- .element: class="fragment fade-in" --> Constructors - base class first, then derived
11+
* <!-- .element: class="fragment fade-in" --> <a href="https://ideone.com/Kgb46n">ideone.com</a>
12+
* <!-- .element: class="fragment fade-in" --> Diamond problem
13+
* <!-- .element: class="fragment fade-in" --> virtual inheritance
14+
* <!-- .element: class="fragment fade-in" --> <code>class</code> from <code>struct</code> inheritance is...
15+
* <!-- .element: class="fragment fade-in" --> <a href="https://ideone.com/Rdd6Uf"><code>private</code></a>
16+
* <!-- .element: class="fragment fade-in" --> <code>struct</code> from <code>class</code> inheritance is...
17+
* <!-- .element: class="fragment fade-in" --> <a href="https://ideone.com/x46OvN"><code>public</code></a>
18+
19+
___
20+
21+
## Inheritance access modifiers
22+
23+
| | <code>public</code> | <code>protected</code> | <code>private</code> |
24+
| :------------------------: | :-------------------------------------------------------: | :-------------------------------------------------------: | :-----------------------------------------------------: |
25+
| **<code>public</code>** | public <!-- .element style="background-color: #0a0;"--> | protected<!-- .element style="background-color: #da0;"--> | private<!-- .element style="background-color: #a00;"--> |
26+
| **<code>protected</code>** | protected<!-- .element style="background-color: #da0;"--> | protected<!-- .element style="background-color: #da0;"--> | private<!-- .element style="background-color: #a00;"--> |
27+
| **<code>private</code>** | private <!-- .element style="background-color: #a00;"--> | private <!-- .element style="background-color: #a00;"--> | private<!-- .element style="background-color: #a00;"--> |

module4/pillars.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!-- .slide: data-background="#111111" -->
2+
3+
# The four pillars of objectivity
4+
5+
* <!-- .element: class="fragment fade-in" --> Abstraction
6+
* <!-- .element: class="fragment fade-in" --> Encapsulation
7+
* <!-- .element: class="fragment fade-in" --> Inheritance
8+
* <!-- .element: class="fragment fade-in" --> Polymorphism

module4/polymorphism.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!-- .slide: data-background="#111111" -->
2+
3+
# Polymorphism
4+
5+
___
6+
7+
## Polymorphism
8+
9+
* <!-- .element: class="fragment fade-in" --> Virtual functions
10+
* <!-- .element: class="fragment fade-in" --> Pure virtual functions (<code>=0</code>)
11+
* <!-- .element: class="fragment fade-in" --> Abstract classes
12+
* <!-- .element: class="fragment fade-in" --> have at least one pure virtual function
13+
* <!-- .element: class="fragment fade-in" --> <code>vtable</code> and <code>vptr</code>
14+
* <!-- .element: class="fragment fade-in" --> implementation of polymorphism
15+
* <!-- .element: class="fragment fade-in" --> constructor of derived class overrides base class records in <code>vtable</code>

module4/post_work.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!-- .slide: data-background="#111111" -->
2+
3+
# Post-work
4+
5+
___
6+
7+
## Post-work
8+
9+
You can work in groups or individually. Fork the Cars repo and submit a Pull Request after you have finished.
10+
11+
1. <!-- .element: class="fragment fade-in" --> Create <code>InvalidGear</code> exception. It should be thrown when someone tries eg. change a gear from 5 to R. It should inherit from one of STL exceptions
12+
2. <!-- .element: class="fragment fade-in" --> Fix interfaces to be easy to use correctly and hard to use incorrectly (like <code>accelerate(-999)</code>)
13+
3. <!-- .element: class="fragment fade-in" --> (Optional) Write a proper unit tests to this code
14+
4. <!-- .element: class="fragment fade-in" --> Read one of below articles. It will be useful for the next lesson
15+
16+
* <!-- .element: class="fragment fade-in" --> <a href="https://www.samouczekprogramisty.pl/solid-czyli-dobre-praktyki-w-programowaniu-obiektowym/">SOLID czyli dobre praktyki w programowaniu obiektowym</a> (in Polish)
17+
* <!-- .element: class="fragment fade-in" --> <a href="https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design">S.O.L.I.D: The First 5 Principles of Object Oriented Design</a> (in English)

0 commit comments

Comments
 (0)