An object isn’t:
1) A link between worlds
2) A collection of procedures
plus data
22
Slide 23
Slide 23 text
An object is:
1) Self-sufficient
2) Representative of
encapsulated data
23
Slide 24
Slide 24 text
A Finder of Prime Numbers
vs
A List of numbers that
returns only primes
24
Slide 25
Slide 25 text
Education & Work life
25
Slide 26
Slide 26 text
No Getters and Setters.
Not even once.
26
Slide 27
Slide 27 text
No Getters and Setters
?! ?!
27
Slide 28
Slide 28 text
Again, don’t treat objects as
bags of data.
Ever.
28
Slide 29
Slide 29 text
Computer-style:
29
Slide 30
Slide 30 text
Human-style:
30
Slide 31
Slide 31 text
“An object works by contracts”
31
Slide 32
Slide 32 text
“An object works by contracts”
Always use interfaces
32
Slide 33
Slide 33 text
Example
“I want results for a Tennis match”
Tennis_31Feb.xlsx
TENNIS.txt
tennis_res.json
Sources:
…
33
Slide 34
Slide 34 text
Example
“I want results for a Tennis match”
Tennis_31Feb.xlsx
TENNIS.txt
tennis_res.json
Sources:
…
ExcelTennisMatch
TextTennisMatch
JsonTennisMatch
34
Slide 35
Slide 35 text
Example
“I want results for a Tennis match”
ExcelTennisMatch
TextTennisMatch
JsonTennisMatch
TennisMatch
GameMatch
implement
extends
35
Slide 36
Slide 36 text
Excel, Text, Json, etc.
Contract stays the same
More Decoupling and more Maintainability
36
Slide 37
Slide 37 text
“A good object should never
change his encapsulated state.”
37
Slide 38
Slide 38 text
“A good object should never
change his encapsulated state.”
38
Be immutable
Slide 39
Slide 39 text
This can
change
State is
the same
39
Slide 40
Slide 40 text
Some benefits
Thread Safety
Avoiding Temporal Coupling
Avoiding side effects
Avoiding identity mutability
(more at http://yegor256.com/2014/06/09/objects-should-be-immutable.html)
40
Slide 41
Slide 41 text
Retirement
41
Slide 42
Slide 42 text
Don’t accept null arguments
Don’t return null
42
Slide 43
Slide 43 text
- Hello, is it a software department?
- Yes.
- Let me talk to your employee "Jeffrey"
please.
- Hold the line please...
- Hello.
- …
43
Slide 44
Slide 44 text
- Hello, is it a software department?
- Yes.
- Let me talk to your employee "Jeffrey"
please.
- Hold the line please...
- Hello.
- Are you NULL?
(more at http://www.yegor256.com/2014/05/13/why-null-is-bad.html)
44
Slide 45
Slide 45 text
There’s more to it,
Let’s save it for another talk
45
Slide 46
Slide 46 text
https://github.com/yegor256/cactoos
46
Slide 47
Slide 47 text
Useful building blocks from
Guava, Apache Commons, JDK
+ EO paradigm
47
Slide 48
Slide 48 text
Meaning…
No null
No code in constructors
No getters and setters
No mutable objects
No static methods, not even private ones
(among other stuff)
48
Slide 49
Slide 49 text
Example 1
49
Slide 50
Slide 50 text
Example 2
50
Slide 51
Slide 51 text
Example 3
51
Slide 52
Slide 52 text
Summing up
52
Slide 53
Slide 53 text
Maintainability
53
Slide 54
Slide 54 text
–W. Edwards Deming
"Build quality into the product rather than
trying to test it in later."
54
Slide 55
Slide 55 text
Quality from the start
Force strict control of code quality.
Ex: Static Analysis -> mandatory
55