$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Kotlin - Padrões e Boas Práticas
Search
Rafael Toledo
November 18, 2017
Programming
1
720
Kotlin - Padrões e Boas Práticas
Apresentada no DevFest Belo Horizonte 2017
Rafael Toledo
November 18, 2017
Tweet
Share
More Decks by Rafael Toledo
See All by Rafael Toledo
Gamedev com Kotlin Native
rafaeltoledo
0
89
Kotlin Multiplataforma: Compartilhando código entre Android e iOS
rafaeltoledo
0
290
Motion Layout
rafaeltoledo
1
150
Pipeline Android
rafaeltoledo
3
170
Android Architecture Components
rafaeltoledo
7
170
What's New in Kotlin 1.3
rafaeltoledo
0
150
An Overview of Multiplatform Kotlin
rafaeltoledo
2
130
Compartilhando Código com Kotlin Multiplataforma
rafaeltoledo
2
270
Android Assíncrono
rafaeltoledo
3
220
Other Decks in Programming
See All in Programming
AIコーディングエージェント(Gemini)
kondai24
0
120
DSPy Meetup Tokyo #1 - はじめてのDSPy
masahiro_nishimi
1
150
Querying Design System デザインシステムの意思決定を支える構造検索
ikumatadokoro
1
1.2k
dnx で実行できるコマンド、作ってみました
tomohisa
0
130
connect-python: convenient protobuf RPC for Python
anuraaga
0
350
無秩序からの脱却 / Emergence from chaos
nrslib
2
12k
手軽に積ん読を増やすには?/読みたい本と付き合うには?
o0h
PRO
1
140
CSC305 Lecture 17
javiergs
PRO
0
270
Microservices Platforms: When Team Topologies Meets Microservices Patterns
cer
PRO
1
900
【レイトレ合宿11】kagayaki_v4
runningoutrate
0
220
モデル駆動設計をやってみよう Modeling Forum2025ワークショップ/Let’s Try Model-Driven Design
haru860
0
230
Micro Frontendsで築いた 共通基盤と運用の試行錯誤 / Building a Shared Platform with Micro Frontends: Operational Learnings
kyntk
1
1.9k
Featured
See All Featured
Fireside Chat
paigeccino
41
3.7k
It's Worth the Effort
3n
187
29k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
1
72
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
69k
Speed Design
sergeychernyshev
33
1.4k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3k
How to Ace a Technical Interview
jacobian
280
24k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Site-Speed That Sticks
csswizardry
13
990
Transcript
None
None
None
None
None
None
None
None
None
User user = new User(); user.setName("Rafael Toledo"); // Obrigatório user.setEmail("
[email protected]
");
// Obrigatório user.setPhone("+55 11 99999-9999"); // Opcional
User user = new User.Builder("Rafael Toledo", "
[email protected]
") .phone("+55 11 99999-9999")
.build();
class User(val name: String, val email: String, val phone: String?
= null) User(name = "Rafael Toledo", email = "
[email protected]
")
class User(val name: String, val email: String, val phone: String?
= null) User(name = "Rafael Toledo", email = "
[email protected]
", phone = "+55 11 99999-9999")
taxCalculator { country = Tax.COUNTRY_BRAZIL period { from = date("2017-01-01")
to = date("2017-10-31") } type = Tax.TYPE_IRPF payment { type = Tax.PAYMENT_BANK_TRANSFER bank { agency = "1234" account = "012345-9" ...
None
fun ViewGroup.inflate(layoutRes: Int, attachToRoot: Boolean = false): View { return
LayoutInflater.from(context).inflate(layoutRes, this, attachToRoot) }
None
None
None
None
None
validateAddress(addressFrom(jsonNode)) validateAddress(jsonNode.toAddress()) private fun JsonNode.toAddress() = Address( getRequired("street").asText(), getRequired("town").asText(), get("postcode")?.asPostCode(),
getRequired("country").asCountryCode())
validateAddress(addressFrom(jsonNode)) validateAddress(jsonNode.toAddress()) private fun JsonNode.toAddress() = Address( getRequired("street").asText(), getRequired("town").asText(), get("postcode")?.asPostCode(),
getRequired("country").asCountryCode())
// Antes enableCheckbox(isFreeDelivery(addressFrom(jsonNode))) // Depois enableCheckbox(jsonNode.toAddress().isFreeDelivery())
// Antes if (userCanEditSubmission(currentUser, submission)) { ... } // After
if (currentUser.canEdit(submission)) { ... }
None
None
None
None
None
None
None
None
None
None
if (savedInstanceState != null) { ... } savedInstanceState?.let { ...
}
None
None
// Confuso if (value?.isTrue ?: false) { ... } //
Parece redundante, mas é mais claro! if (value?.isTrue == true) { ... }
None
None
None
None
None
None
None
None
None
None
None
None
None
None
@Deprecated("Use X instead") @Throws(ExceptionInInitializerError::class) fun relevantMethod() { ... }
None
// Em vez de apply plugin: "kotlin-android" apply plugin: "kotlin-android-extensions"
// Por que não... apply plugin: "org.jetbrains.kotlin.android" apply plugin: "org.jetbrains.kotlin.android.extensions" apply plugin: "org.jetbrains.kotlin.kapt"
None
None
None