9
9
### Agenda
10
10
11
11
* Problem
12
- * IO
13
12
* Ports & Adapters
14
13
* Abstraction
15
14
* Other
@@ -90,56 +89,6 @@ So each call to `GeneateInvoice` increments invoice number :(
90
89
91
90
![ Invoice-lang-fp] ( ./img/invoice-lang-fp.png )
92
91
93
-
94
- ---
95
-
96
- ## IO
97
-
98
- * IO is from Haskell
99
- * Used to force inpure code away from pure code
100
- * Baked in to Haskell type system
101
-
102
- ----
103
-
104
- ### Monad
105
-
106
- So IO would be all the places we have side-effects aka. Infrastructure
107
-
108
- * IO is a monad\* .
109
- * Another example of monads is F#'s ` Option `
110
- * Monads can be combined with '` bind ` '
111
-
112
- \* We will come back to monads. <!-- .element: style="font-size: 20px; position: relative; bottom:0;" -->
113
-
114
- ----
115
-
116
- #### Return and Bind
117
-
118
- Two important methods for Monads are '` return ` ' and '` bind ` '
119
-
120
- ``` fsharp
121
- val return: 'a -> M<'a>
122
- val bind: M<'a> -> ('a -> M<'b>) -> M<'b>
123
- ```
124
-
125
-
126
- note:
127
-
128
- Monads also have some rules
129
-
130
- ----
131
-
132
- #### Example with F#'s Option
133
-
134
- ``` fsharp
135
- let o = Some 3 // creation or return
136
- let n = None // creation or return
137
- let f = fun a -> Some (a+3)
138
-
139
- o |> Option.bind f // ...
140
- n |> Option.bind f // ...
141
- ```
142
-
143
92
---
144
93
145
94
#### Hexagonal architecture
@@ -154,18 +103,20 @@ By Alistair Cockburn
154
103
155
104
## Ports & Adapters
156
105
157
- * Components
106
+ * Components<!-- .element: class="fragment" -->
158
107
* loosely coupled and interchangeable
159
108
* e.g. database, ui, business logic, etc. etc.
160
- * Ports
161
- * 'holes ' that components can access other components through
162
- * Adapters
109
+ * Ports<!-- .element: class="fragment" -->
110
+ * 'interface ' that components can access other components through
111
+ * Adapters<!-- .element: class="fragment" -->
163
112
* glue between components and ports
164
113
165
114
Note: Not only for FP - but very used especially in FP so e.g. F# and Haskell
166
115
167
116
----
168
117
118
+ <!-- TODO: New example -->
119
+
169
120
### A Resturant example
170
121
171
122
``` fsharp
@@ -214,15 +165,15 @@ let getReservedSeats = getReservedSeatsFromDb connStr
214
165
// val getReservedSeats : (Reservation -> int)
215
166
```
216
167
217
- So '` getReservedSeats ` ' are inpure - but that do not show in the signature.
168
+ * <!-- .element: class="fragment" --> So 'getReservedSeats' are inpure - but that do not show in the signature.
218
169
219
170
----
220
171
221
- ### 'Problem'
172
+ ### Partial application
222
173
223
- * Our pure function '` check ` ', will be inpure in production
174
+ * <!-- .element: class="fragment" --> Our pure function 'check', will be inpure in production
224
175
225
- * But why do checkCapacity need getReservedSeats at all? <!-- .element: class="fragment" -->
176
+ * But why do 'check' need getReservedSeats at all? <!-- .element: class="fragment" -->
226
177
227
178
----
228
179
@@ -268,26 +219,28 @@ let add1Times2' = add1 >> times2
268
219
269
220
### Reuse logic
270
221
271
- * What is business logic?
272
- * What is application logic?
273
- * Should ` reserveTable ` belong in the business logic layer?
222
+ * What is business logic?< br /> <!-- .element: class="fragment" -->
223
+ * What is application logic?< br /> <!-- .element: class="fragment" -->
224
+ * Does ' reserveTable' belong in the BLL?< br /> <!-- .element: class="fragment" -->
274
225
275
226
----
276
227
277
- The function ` reserveTable `
278
- 1 . could also argue that this function is part of the controller
279
- 2 . thereby not something you would reuse in another application
280
- 3 . because:
281
- * would you always need to handle resevation validation?
228
+ ### The function ` reserveTable `
229
+
230
+ 1 . could application logic<br /><!-- .element: class="fragment" -->
231
+ 1 . thereby not something you would nessesary reuse<br /><!-- .element: class="fragment" -->
232
+ 1 . because:<br /><!-- .element: class="fragment" -->
233
+ * handle resevation validation in the same manner?
282
234
* handle input/output different
283
235
284
236
----
285
237
286
- ### Generalization
238
+ ### Take-aways
287
239
288
- 1 . Read data from impure sources
289
- 2 . Hand data to BLL
290
- 3 . Use returned data to perform side-effects
240
+ 1 . Read data (impure)<br /><!-- .element: class="fragment" -->
241
+ 1 . Hand data to BLL (pure)<br /><!-- .element: class="fragment" -->
242
+ 1 . Save data (impure)<br /><!-- .element: class="fragment" -->
243
+ 1 . Return/show data (impure)<br /><!-- .element: class="fragment" -->
291
244
292
245
---
293
246
@@ -314,33 +267,31 @@ Is my function `a()` pure or not?
314
267
----
315
268
316
269
### Ports and Adapters
317
- ##### hexagonal architecture
318
-
319
- * To avoid DAL to contaminate e.g. BLL
320
- * Alternative to layered architecture
321
- * Each component is connected through a number of ports
322
-
270
+ ##### or hexagonal architecture
323
271
324
- ** Note** : Not always the correct solution
272
+ * One way of avoiding DAL contaminating BLL<br /><!-- .element: class="fragment" -->
273
+ * Alternative to layered architecture<br /><!-- .element: class="fragment" -->
274
+ * Each component is connected through a number of ports<br /><!-- .element: class="fragment" -->
275
+ * <!-- .element: class="fragment" --> Not always the correct solution
325
276
326
277
----
327
278
328
279
### Onion architecture
329
280
330
281
![ Onion architecture] ( ./img/onion-architecture.png ) <!-- .element style="height: 260px" -->
331
282
332
- * Onion architecture was inspired by Hexogonal architecture
333
- * Layered architecture
283
+ * Onion architecture was inspired by Hexogonal architecture< br /> <!-- .element: class="fragment" -->
284
+ * Layered architecture<!-- .element: class="fragment" -->
334
285
* where inner circles have no knowledge of outer circle
335
286
336
287
337
288
----
338
289
339
- ### Onion pro/cons
290
+ ### Onion Arch. pro/cons
340
291
341
- * \- e.g. database is accessible from UI
292
+ * \- e.g. database is accessible from UI< br /> <!-- .element: class="fragment" -->
342
293
* they are in same layer - not a good idea though.
343
- * \+ fewer artifacts then ports and adapters
294
+ * \+ fewer artifacts then ports and adapters< br /> <!-- .element: class="fragment" -->
344
295
345
296
---
346
297
@@ -353,6 +304,7 @@ Looks like microservices, right?
353
304
----
354
305
355
306
### Pipe and filter
307
+ ##### or reactive programming
356
308
357
309
![ Pipe and Filter] ( ./img/pipe-and-filter.jpg " https://csblogpro.wordpress.com/2017/11/05/pipe-and-filter-architecture/ ")
358
310
0 commit comments