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
Building stable and flexible libraries
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Keishin Yokomaku
December 17, 2014
Technology
3.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Building stable and flexible libraries
Keishin Yokomaku
December 17, 2014
More Decks by Keishin Yokomaku
See All by Keishin Yokomaku
Base64 in Android
keithyokoma
0
55
One screen, many BottomSheets
keithyokoma
0
460
LazyColumnのitemがViewPortの中で占める領域の割合を知りたい
keithyokoma
0
760
Build apps for Cars
keithyokoma
0
600
Save the state
keithyokoma
0
630
Either in Kotlin
keithyokoma
0
650
持続的なアプリ開発のためのDXを支える技術
keithyokoma
2
5.6k
Make the objects serializable with kotlinx.serialization
keithyokoma
0
5.4k
Kotlin で書く Gradle Custom Tasks
keithyokoma
0
590
Other Decks in Technology
See All in Technology
FORENSIA: ローカルLLMフォレンジックハーネス
sumeshi
2
270
20260608_Codexの可能性_ノンプログラマー向け_大城追記
doradora09
PRO
0
780
TypeScript入門 2026
recruitengineers
PRO
2
480
ラジオの科学
frievea
0
270
Master Dataグループ紹介資料
sansan33
PRO
1
4.8k
ボトムアップ文化が強い組織で セキュリティをどう根付かせていくかの現在進行形の話 / Making Security Stick in a Bottom-Up Organization
yamaguchitk333
0
200
SnowflakeCoCoでデータエンジニアリング!
foursue
0
180
第3回しろおびセキュリティスポンサーセッション
log0417
0
150
ガバメントクラウドでのランサムウェア対策
techniczna
2
940
【CEDEC2026】次世代デジタルカードゲームのサーバー設計と運用 〜『Shadowverse: Worlds Beyond』の舞台裏~
cygames
PRO
1
950
Bill One 開発エンジニア 紹介資料
sansan33
PRO
7
19k
20260804_Q4AzureUpdateBite_FabricDataAgentの精度を高める設計.pdf
matayuuu
1
110
Featured
See All Featured
Accessibility Awareness
sabderemane
1
170
Evolving SEO for Evolving Search Engines
ryanjones
0
250
The Limits of Empathy - UXLibs8
cassininazir
1
590
Leo the Paperboy
mayatellez
8
2.1k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
330
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
73
41k
Music & Morning Musume
bryan
47
7.3k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Transcript
Building stable and flexible libraries @KeithYokoma - Drivemode, Inc. potatotips
#12
KeithYokoma Keishin Yokomaku Drivemode, Inc. Android Engineer GitHub: https://github.com/KeithYokoma e-Book:
http://amzn.to/1mZNydv
Agenda • Stability • Flexibility
Make libraries STABLE
Make libraries STABLE • Entity class declaration • Multi-thread compatibility
• Lifecycle management
Make libraries STABLE • Entity class declaration • Don’t •
Do void setToken(String token, String type, String refresh, long by); void setToken(AccessToken token);
Make libraries STABLE • Entity class declaration • Hard to
remember the type of args • Not Type-Safe(ref. Effective Java) void setToken(String token, String type, String refresh, long by);
• Entity class declaration • Easy to remember the type
of args • Type-Safe void setToken(AccessToken token); Make libraries STABLE
Make libraries STABLE • Multi-thread compatibility • Synchronization • Immutable
entity • Thread pool and callback lifecycle • Singleton implementation
Make libraries STABLE • Multi-thread compatibility • Synchronization • “synchronized”
block • Synchronization utils(CyclicBarrier, …) • Atomicity(AtomicInteger, …) • “volatile” field
Make libraries STABLE • Multi-thread compatibility • Immutable entity •
Immutable entity is thread safe
Make libraries STABLE • Multi-thread compatibility • Thread pool and
callback lifecycle • Reduce thread initialization cost • Align callback lifetime with “Context” • Do NOT callback to dead object
Make libraries STABLE • Multi-thread compatibility • Singleton implementation •
Be aware of “Lazy Initialization”
// NOT thread safe!! public class Singleton { private static
Singleton sInstance; public static Singleton getInstance() { if (sInstance == null) { sInstance = new Singleton(); } return sInstance; } } Case Study Multi-thread compatibility
Make libraries STABLE • Multi-thread compatibility • Singleton implementation •
“synchronized” block • Double checked locking • Initialization on demand holder
private static Singleton sInstance; public static synchronized Singleton getInstance() {
if (sInstance == null) { sInstance = new Singleton(); } return sInstance; } Case Study Multi-thread compatibility
private static volatile Singleton sInstance; public static Singleton getInstance() {
if (sInstance == null) { synchronized (Singleton.class) { if (sInstance == null) { sInstance = new Singleton(); } } } return sInstance; } Case Study Multi-thread compatibility
static class Holder { public static final Singleton SINGLETON =
new Singleton(); } public static getInstance() { return Holder.SINGLETON; } Case Study Multi-thread compatibility
Make libraries STABLE • Lifecycle management • Object lifetime alignment
Make libraries STABLE • Lifecycle management • Object lifetime alignment
• Lifecycle methods of various “Context” • onCreate/onDestroy • onStart/onStop, onResume/onPause
Make libraries STABLE • Lifecycle management • Object lifetime alignment
• Naming convention • add/remove, register/unregister • start/finish, initialize/destroy
Make libraries FLEXIBLE
Make libraries FLEXIBLE • Annotations vs Listeners • Customizable resources
• Split package by domain
Make libraries FLEXIBLE • Annotations ✓ Fast and easy development
for client ✓ Automatic code generation(with apt) ✗ Slow(both runtime and apt takes time) ✗ Hard to dig into library itself
Make libraries FLEXIBLE • Listeners ✓ Faster than annotations(runtime) ✓
Simple architecture ✗ Client should maintain the lifetime
Make libraries FLEXIBLE • Annotations and Listeners • Do NOT
call methods of dead object
• Customizable resources • If the library has UI resources…
• Theme should be customizable • What about layout resources? Make libraries FLEXIBLE
• Customizable resources • At least you need to… •
Define ID resources that the library uses • Otherwise layout may not be customized Make libraries FLEXIBLE
Make libraries FLEXIBLE • Split package by domain • Avoid
exceeding 65k method limit • Less effort to strip out codes not used
Make libraries FLEXIBLE • Split package by domain • e.g.
Guava • guava, guava-gwt, guava-annotations, … • e.g. Google Play Services 6.5 • play-services, play-services-wearable, …
–Joshua Bloch “Never make the client do anything the library
can do for the client.”
Building stable and flexible libraries @KeithYokoma - Drivemode, Inc. potatotips
#12