/
index.html
359 lines (328 loc) · 11.2 KB
/
index.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Object oriented code. So fancy. What's the point?</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/drupaldevdays.css">
<style>
.dark h1,
.dark h2,
.dark,
.dark a {
color: #fff;
}
</style>
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-background="css/images/cover.png">
<h1>Object oriented code. So fancy. What's the point?</h1>
<p>
<small><a href="#">Eirik S. Morland / @orkj / eiriksm</a></small>
</p>
</section>
<section data-markdown data-background="css/images/cover.png">
# About me
- Work at Ny Media (Trondheim, Norway)
- eiriksm on [drupal.org](https://www.drupal.org/u/eiriksm) / [github](https://github.com/eiriksm/)
- [@orkj at twitter](https://twitter.com/orkj)
- Beer nerd
- Fan of the image format GIF
</section>
<section data-markdown data-background="css/images/cover.png">
## Prolific author of the wildly popular paradigm "display:none-driven-development"
</section>
<section class="has-dark-background section-slide" data-background="css/images/section.png" >
<img class="stretch" src="img/fix.png" />
</section>
<section class="has-dark-background section-slide" data-background="css/images/section.png" >
<img class="stretch" src="img/enable.png" />
</section>
<section data-background="img/display.gif">
<aside class="notes" data-markdown>
- Why talk about it?
- Establish authority
</aside>
</section>
<section data-markdown class="has-dark-background section-slide" data-background="css/images/section.png" >
# Object oriented programming
> Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects" (...)
<small>Wikipedia</small>
</section>
<section data-background="img/oop.gif">
</section>
<section data-markdown data-background="css/images/cover.png">
## What we will cover
- Very briefly: What is OOP in PHP?
- Why are we doing that in Drupal 8 now?
- Is it even better, though? Examples?
</section>
<section data-markdown data-background="css/images/cover.png">
## Let's look at some examples of what OOP in PHP means.
</section>
<section class="has-dark-background section-slide" data-background="css/images/section.png" >
<pre><code><?php
function print_hello_world() {
print "Hello world!";
}
print_hello_world(); // Prints "Hello world!"
</code></pre>
</section>
<section class="has-dark-background section-slide" data-background="css/images/section.png" >
<pre><code><?php
namespace Long\String\With\Backslashes;
class HelloWorldPrinterFactory implements HelloWorldPrinterFactoryInterface {
public function getHelloWorldPrinter() {
return new HelloWorldPrinter();
}
}
class HelloWorldPrinter implements PrinterInterface {
protected $hello = 'Hello';
protected $world = 'world!';
public function printHelloWorld(Another\String\With\Backslashes\PrintThings $thingPrinter) {
return $thingPrinter->printThing($this->getHello() . ' ' . $this->getWorld());
}
private function getHello() {
return $this->hello;
}
private function getWorld() {
return $this->world;
}
}
new HelloWorldPrinterFactory()
->getHelloWorldPrinter()
->printHelloWorld(new Another\String\With\Backslashes\PrintThings()); // Prints "Hello world!"
</code></pre>
</section>
<section data-markdown data-background="css/images/cover.png">
# At first sight.
## That looks horrible.
</section>
<section data-background="img/yuck.gif">
</section>
<section class="has-dark-background section-slide" data-background="css/images/section.png" >
<h5>mymodule.module</h5>
<code><pre>
<?php
function mymodule_block_info() {
return array(
'my_block' => array(
'info' => t('My block'),
),
);
}
function mymodule_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'my_block':
$block['subject'] = t('My block');
$block['content'] = t('This is some content.');
break;
}
return $block;
}
</code></pre>
</section>
<section class="has-dark-background section-slide" data-background="css/images/section.png" >
<h5>src/Plugin/Block/MyBlock.php</h5>
<code><pre>
<?php
namespace Drupal\mymodule\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* @Block(
* id = "my_block",
* admin_label = @Translation("My block"),
* )
*/
class MyBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
return array(
'#markup' => $this->t('This is some content.'),
);
}
}
</code></pre>
</section>
<section data-markdown data-background="css/images/cover.png">
# At first sight.
## That also looks horrible.
</section>
<section data-markdown class="has-dark-background section-slide" data-background="css/images/section.png" >
### Some statements I read (citations omitted on purpose)
- (...) well established as a best practice
- Faster development thanks to re-use
- Encapsulation
- Easier to test
- Better, because... Dependency injection?
- Fewer bugs because... Objects?
</section>
<section data-background="img/risky.gif" data-markdown class="has-dark-background dark">
## First statement
Well established as a best practice
</section>
<section data-markdown data-background="css/images/cover.png">
### Which one of these is not from Drupal core, but from a Java program
- ExecutionContextFactory
- ReflectionFactory
- MemoryBackendFactory
- ServiceFactory
</section>
<section data-markdown data-background="css/images/cover.png">
### Which one of these is not from Drupal core, but from a Java program
- ~~ExecutionContextFactory~~
- ~~ReflectionFactory~~
- ~~MemoryBackendFactory~~
- ServiceFactory
</section>
<section data-background="img/reusable.gif">
<div class="slide" data-markdown>
# Sorry. First statement
## Faster development thanks to re-use
</div>
</section>
<section data-background="css/images/cover.png">
<div class="slide" data-markdown>
# Look at code, Eirik
</div>
<aside class="notes" data-markdown>
- Blockbase vs hook_block
- Remove extends
- Add form
- Textformatter (function view, $this->getSetting('trim_length')), form for it
</aside>
</section>
<section data-markdown data-background="img/encap.gif">
# Second statement
## Encapsulation
</section>
<section data-background="css/images/cover.png">
<div class="slide" data-markdown>
# Look at code, Eirik
</div>
<aside class="notes" data-markdown>
- Drupal 7 global user
- Drupal 8 global user, $uid, getAccount uid, setInitialAccountId, setAccount
</aside>
</section>
<section data-markdown data-background="img/test.gif" class="dark">
# Third statement
Easier to test
</section>
<section class="has-dark-background section-slide" data-background="css/images/section.png" >
<pre><code><?php
function user_adder_add_numbers($num_a, $num_b) {
return $num_a + $num_b;
}
assert(user_adder_add_numbers(1, 2) === 3);
</code></pre>
</section>
<section class="has-dark-background section-slide" data-background="css/images/section.png" >
<pre><code><?php
class Adder {
public function addNumbers($a, $b) {
return $a + $b;
}
}
$a = new Adder();
assert($a->addNumbers(1, 2) === 3);
</code></pre>
</section>
<section data-background="css/images/cover.png">
<div class="slide" data-markdown>
# Look at code, Eirik
</div>
<aside class="notes" data-markdown>
- DenyNodePreview
</aside>
</section>
<section data-markdown data-background="img/di.gif" class="dark">
# Dependency injection
</section>
<section data-background="css/images/cover.png">
<div class="slide" data-markdown>
# Look at code, Eirik
</div>
<aside class="notes" data-markdown>
- inject global user (d7)
- Look at userLoginBlock
- Look at that notifier
</aside>
</section>
<section data-background="img/object.gif" data-markdown>
# Fewer bugs because... Objects?
</section>
<section class="has-dark-background section-slide" data-background="css/images/section.png" >
<pre><code><?php
public function handleSomeThing(NodeInterface $node) {
$node->getType(); // Always exists!
}
</code></pre>
</section>
<section data-background="css/images/cover.png">
<div class="slide" data-markdown>
# Look at code, Eirik
</div>
<aside class="notes" data-markdown>
- Type hint user
- Nodeinterface user
- gettypo
- refacactor logger
</aside>
</section>
<section data-background="img/conclusion.gif" data-markdown class="dark">
# Trying to sum it up.
</section>
<section data-markdown data-background="css/images/base.png">
## Summary
- Might look (one or more of) the following things: scary, hard, ugly and like a lot of work.
- May or may not be your taste.
- Might give you some benefits.
- Benefits are more obvious when using an IDE.
</section>
<section data-markdown class="has-dark-background dark section-slide" data-background="img/thanks.gif">
# Thanks!
## Questions?
- [eiriksm.github.io/devdays-seville-17](https://eiriksm.github.io/devdays-seville-17)
- [@orkj](http://twitter.com/orkj)
</section>
<!-- Please consider keeping this slide since DrupalDevDays is possible thanks to sponsors. -->
<section data-background="css/images/base.png">
<h2>THANKS!</h2>
<img data-src="css/images/sponsors.png">
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
history: true,
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>