Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Elegant Objects and Cactoos
Search
Filipe Freire
December 21, 2017
Programming
0
230
Elegant Objects and Cactoos
Overview of the EO paradigm and small overview of the Cactoos library for Porto Codes Meetup
Filipe Freire
December 21, 2017
Tweet
Share
More Decks by Filipe Freire
See All by Filipe Freire
Deep Testing
filipe
0
78
Finding Tranquility
filipe
0
71
Quality Foundations
filipe
0
69
Tacit CSS Framework
filipe
0
280
Quality from the start
filipe
0
120
Tacit
filipe
0
140
Waiting is boring
filipe
0
470
You don't need a DevOps to "be DevOps"
filipe
0
290
Other Decks in Programming
See All in Programming
エラーレスポンス設計から考える、0→1開発におけるGraphQLへの向き合い方
bicstone
5
1.5k
connect-go で面倒くささと戦う / 2024-08-27 #newmo_layerx_go
izumin5210
2
620
実践 Advanced CallKit 〜快適な通話の実現に向けて〜
mot_techtalk
3
120
Kotlin 2.0が与えるAndroid開発の進化
masayukisuda
1
260
エンジニア1年目で複雑なコードの改善に取り組んだ話
mtnmr
2
1.7k
Appleの新しいプライバシー要件対応: ノーコードアプリ プラットフォームの実践事例
nao_randd
1
610
Using Livebook to build and deploy internal tools @ ElixirConf 2024
hugobarauna
0
240
Amebaチョイス立ち上げの裏側 ~依存システムとの闘い~
daichi_igarashi
0
230
デザインシステムとコンポーネント指向によるフロントエンド開発プロセスの革新 / Innovation in Frontend Development Processes through Design Systems and Component-Oriented Architecture
nrslib
8
5.3k
『ドメイン駆動設計をはじめよう』中核の業務領域
masuda220
PRO
5
960
Architecture Decision Record (ADR)
nearme_tech
PRO
1
650
The Shape of a Service Object
inem
0
440
Featured
See All Featured
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
23
1.7k
GitHub's CSS Performance
jonrohan
1029
450k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Building a Modern Day E-commerce SEO Strategy
aleyda
35
6.8k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
354
29k
Navigating Team Friction
lara
183
13k
Clear Off the Table
cherdarchuk
91
320k
The Invisible Side of Design
smashingmag
295
50k
Statistics for Hackers
jakevdp
793
220k
Making the Leap to Tech Lead
cromwellryan
128
8.8k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
190
16k
Transcript
Elegant objects & Cactoos Filipe Freire 21 December 2017
Quick intro Learner, tester, developer, husband OSS contributor 2y work
as a “coding” tester 1y work as a developer Currently @ filfreire.com 2
Elegant Objects 3
It’s an OOP paradigm 4
Book Yegor Bugayenko @yegor256 www.yegor256.com 5
Book Yegor Bugayenko @yegor256 www.yegor256.com Set of recommendations: - Cleaner
code - Better classes - Visible architecture 6
Disclaimer: You can find out more at yegor256.com Youtube @yegor256
and on the EO books. 7
So, what are the recommendations? 8
Getters Setters Mutable objects Static methods Annotations Data Objects Type
Casting Etc. 9
Getters Setters Mutable objects Static methods Annotations Data Objects Type
Casting Etc. 10
Don’t treat objects as data structures bags of data.
Ever. 11
Maintainability > everything else 12
“Objects as living beings” Birth Working life Retirement 13
Some examples… 14
Birth 15
Code Free Constructors 16
17
“Object’s name != job title” 18
Object’s name != job title Meaning: Avoid the use of
“-ER” 19
Helper, Handler, Writer, Reader, Converter, Observer, Listener, Sorter, Encoder, Decoder,
… 20
Helper, Handler, Writer, Reader, Converter, Observer, Listener, Sorter, Encoder, Decoder,
… 21
An object isn’t: 1) A link between worlds 2) A
collection of procedures plus data 22
An object is: 1) Self-sufficient 2) Representative of encapsulated
data 23
A Finder of Prime Numbers vs A List of numbers
that returns only primes 24
Education & Work life 25
No Getters and Setters. Not even once. 26
No Getters and Setters ?! ?! 27
Again, don’t treat objects as bags of data. Ever.
28
Computer-style: 29
Human-style: 30
“An object works by contracts” 31
“An object works by contracts” Always use interfaces 32
Example “I want results for a Tennis match” Tennis_31Feb.xlsx TENNIS.txt
tennis_res.json Sources: … 33
Example “I want results for a Tennis match” Tennis_31Feb.xlsx TENNIS.txt
tennis_res.json Sources: … ExcelTennisMatch TextTennisMatch JsonTennisMatch 34
Example “I want results for a Tennis match” ExcelTennisMatch TextTennisMatch
JsonTennisMatch TennisMatch GameMatch implement extends 35
Excel, Text, Json, etc. Contract stays the same More Decoupling
and more Maintainability 36
“A good object should never change his encapsulated state.” 37
“A good object should never change his encapsulated state.” 38
Be immutable
This can change State is the same 39
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
Retirement 41
Don’t accept null arguments Don’t return null 42
- Hello, is it a software department? - Yes. -
Let me talk to your employee "Jeffrey" please. - Hold the line please... - Hello. - … 43
- 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
There’s more to it, Let’s save it for another talk
45
https://github.com/yegor256/cactoos 46
Useful building blocks from Guava, Apache Commons, JDK + EO
paradigm 47
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
Example 1 49
Example 2 50
Example 3 51
Summing up 52
Maintainability 53
–W. Edwards Deming "Build quality into the product rather than
trying to test it in later." 54
Quality from the start Force strict control of code quality.
Ex: Static Analysis -> mandatory 55
Thank you. Questions? filfreire filrfreire filfreire.com 56