SlideShare a Scribd company logo
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

More Related Content

What's hot

The Three Musketeers
The Three MusketeersThe Three Musketeers
The Three Musketeers
Frederic Lemay
 
SFJS 6-19-2012
SFJS 6-19-2012SFJS 6-19-2012
SFJS 6-19-2012
Adam Christian
 
rsyslog meets docker
rsyslog meets dockerrsyslog meets docker
rsyslog meets docker
Rainer Gerhards
 
IPv6 & Containers
IPv6 & ContainersIPv6 & Containers
IPv6 & Containers
Pieter Lewyllie
 
Advanced SQL Injection with SQLol
Advanced SQL Injection with SQLolAdvanced SQL Injection with SQLol
Advanced SQL Injection with SQLol
BaronZor
 
Service stack all the things
Service stack all the thingsService stack all the things
Service stack all the things
cyberzeddk
 
Introduction to Openstack - nova
Introduction to Openstack - novaIntroduction to Openstack - nova
Introduction to Openstack - nova
Junho Kim
 
Introduction to Docker - Docker workshop @Twitter
Introduction to Docker - Docker workshop @TwitterIntroduction to Docker - Docker workshop @Twitter
Introduction to Docker - Docker workshop @Twitter
dotCloud
 
Innovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXCInnovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXC
kscaldef
 
Docker Practical Use Cases
Docker Practical Use CasesDocker Practical Use Cases
Docker Practical Use Cases
Alexei Yuzhakov
 
Tampering with JavaScript
Tampering with JavaScriptTampering with JavaScript
Tampering with JavaScript
Boy Baukema
 
Atmosphere packages and the chuck norris effect
Atmosphere packages and the chuck norris effectAtmosphere packages and the chuck norris effect
Atmosphere packages and the chuck norris effect
Fabian Kromer
 
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Valeri Karpov
 
Reactive applications and microservices with Vert.x tool-kit
Reactive applications and microservices with Vert.x tool-kitReactive applications and microservices with Vert.x tool-kit
Reactive applications and microservices with Vert.x tool-kit
Victor Hugo
 
Steamlining your puppet development workflow
Steamlining your puppet development workflowSteamlining your puppet development workflow
Steamlining your puppet development workflow
Tomas Doran
 

What's hot (15)

The Three Musketeers
The Three MusketeersThe Three Musketeers
The Three Musketeers
 
SFJS 6-19-2012
SFJS 6-19-2012SFJS 6-19-2012
SFJS 6-19-2012
 
rsyslog meets docker
rsyslog meets dockerrsyslog meets docker
rsyslog meets docker
 
IPv6 & Containers
IPv6 & ContainersIPv6 & Containers
IPv6 & Containers
 
Advanced SQL Injection with SQLol
Advanced SQL Injection with SQLolAdvanced SQL Injection with SQLol
Advanced SQL Injection with SQLol
 
Service stack all the things
Service stack all the thingsService stack all the things
Service stack all the things
 
Introduction to Openstack - nova
Introduction to Openstack - novaIntroduction to Openstack - nova
Introduction to Openstack - nova
 
Introduction to Docker - Docker workshop @Twitter
Introduction to Docker - Docker workshop @TwitterIntroduction to Docker - Docker workshop @Twitter
Introduction to Docker - Docker workshop @Twitter
 
Innovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXCInnovating faster with SBT, Continuous Delivery, and LXC
Innovating faster with SBT, Continuous Delivery, and LXC
 
Docker Practical Use Cases
Docker Practical Use CasesDocker Practical Use Cases
Docker Practical Use Cases
 
Tampering with JavaScript
Tampering with JavaScriptTampering with JavaScript
Tampering with JavaScript
 
Atmosphere packages and the chuck norris effect
Atmosphere packages and the chuck norris effectAtmosphere packages and the chuck norris effect
Atmosphere packages and the chuck norris effect
 
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
 
Reactive applications and microservices with Vert.x tool-kit
Reactive applications and microservices with Vert.x tool-kitReactive applications and microservices with Vert.x tool-kit
Reactive applications and microservices with Vert.x tool-kit
 
Steamlining your puppet development workflow
Steamlining your puppet development workflowSteamlining your puppet development workflow
Steamlining your puppet development workflow
 

Similar to Building stable and flexible libraries

The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
Alex Payne
 
Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
Manish Pandit
 
06 integrate elasticsearch
06 integrate elasticsearch06 integrate elasticsearch
06 integrate elasticsearch
Erhwen Kuo
 
Search and analyze your data with elasticsearch
Search and analyze your data with elasticsearchSearch and analyze your data with elasticsearch
Search and analyze your data with elasticsearch
Anton Udovychenko
 
Devoxx UK 2015: How Java EE has changed pattern implementation
Devoxx UK 2015: How Java EE has changed pattern implementationDevoxx UK 2015: How Java EE has changed pattern implementation
Devoxx UK 2015: How Java EE has changed pattern implementation
Alex Theedom
 
Arquillian
ArquillianArquillian
Arquillian
nukeevry1
 
Persistent storage tailored for containers #dockersummit
Persistent storage tailored for containers #dockersummitPersistent storage tailored for containers #dockersummit
Persistent storage tailored for containers #dockersummit
Infinit
 
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...seleniumconf
 
Variables in Pharo
Variables in PharoVariables in Pharo
Variables in Pharo
Marcus Denker
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
Iulian Dragos
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaWO Community
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and FallaciesRoman Elizarov
 
SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016
Alex Theedom
 
Java EE Revisits Design Patterns
Java EE Revisits Design PatternsJava EE Revisits Design Patterns
Java EE Revisits Design Patterns
Alex Theedom
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
SATOSHI TAGOMORI
 
Java EE revisits design patterns
Java EE revisits design patternsJava EE revisits design patterns
Java EE revisits design patterns
Alex Theedom
 
Java EE revisits design patterns
Java EE revisits design patterns Java EE revisits design patterns
Java EE revisits design patterns
Alex Theedom
 
DevOps Odessa #TechTalks 21.01.2020
DevOps Odessa #TechTalks 21.01.2020DevOps Odessa #TechTalks 21.01.2020
DevOps Odessa #TechTalks 21.01.2020
Lohika_Odessa_TechTalks
 
JavaScript: Creative Coding for Browsers
JavaScript: Creative Coding for BrowsersJavaScript: Creative Coding for Browsers
JavaScript: Creative Coding for Browsersnoweverywhere
 

Similar to Building stable and flexible libraries (20)

The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Javasession6
Javasession6Javasession6
Javasession6
 
Java and the JVM
Java and the JVMJava and the JVM
Java and the JVM
 
06 integrate elasticsearch
06 integrate elasticsearch06 integrate elasticsearch
06 integrate elasticsearch
 
Search and analyze your data with elasticsearch
Search and analyze your data with elasticsearchSearch and analyze your data with elasticsearch
Search and analyze your data with elasticsearch
 
Devoxx UK 2015: How Java EE has changed pattern implementation
Devoxx UK 2015: How Java EE has changed pattern implementationDevoxx UK 2015: How Java EE has changed pattern implementation
Devoxx UK 2015: How Java EE has changed pattern implementation
 
Arquillian
ArquillianArquillian
Arquillian
 
Persistent storage tailored for containers #dockersummit
Persistent storage tailored for containers #dockersummitPersistent storage tailored for containers #dockersummit
Persistent storage tailored for containers #dockersummit
 
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
Testing Rapidly Changing Applications With Self-Testing Object-Oriented Selen...
 
Variables in Pharo
Variables in PharoVariables in Pharo
Variables in Pharo
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
Java Serialization Facts and Fallacies
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
 
SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016SE2016 - Java EE revisits design patterns 2016
SE2016 - Java EE revisits design patterns 2016
 
Java EE Revisits Design Patterns
Java EE Revisits Design PatternsJava EE Revisits Design Patterns
Java EE Revisits Design Patterns
 
Ruby and Distributed Storage Systems
Ruby and Distributed Storage SystemsRuby and Distributed Storage Systems
Ruby and Distributed Storage Systems
 
Java EE revisits design patterns
Java EE revisits design patternsJava EE revisits design patterns
Java EE revisits design patterns
 
Java EE revisits design patterns
Java EE revisits design patterns Java EE revisits design patterns
Java EE revisits design patterns
 
DevOps Odessa #TechTalks 21.01.2020
DevOps Odessa #TechTalks 21.01.2020DevOps Odessa #TechTalks 21.01.2020
DevOps Odessa #TechTalks 21.01.2020
 
JavaScript: Creative Coding for Browsers
JavaScript: Creative Coding for BrowsersJavaScript: Creative Coding for Browsers
JavaScript: Creative Coding for Browsers
 

More from Keishin Yokomaku

UI optimization for night
UI optimization for nightUI optimization for night
UI optimization for night
Keishin Yokomaku
 
Popup view on Mortar
Popup view on MortarPopup view on Mortar
Popup view on Mortar
Keishin Yokomaku
 
Regexp in Android and Java
Regexp in Android and JavaRegexp in Android and Java
Regexp in Android and Java
Keishin Yokomaku
 
Deep Inside Android Hacks
Deep Inside Android HacksDeep Inside Android Hacks
Deep Inside Android Hacks
Keishin Yokomaku
 
Make it compatible
Make it compatibleMake it compatible
Make it compatible
Keishin Yokomaku
 
Signature
SignatureSignature
Signature
Keishin Yokomaku
 
Android Media Hacks
Android Media HacksAndroid Media Hacks
Android Media Hacks
Keishin Yokomaku
 
Null, the Abyss
Null, the AbyssNull, the Abyss
Null, the Abyss
Keishin Yokomaku
 
?
??
Typeface
TypefaceTypeface
Version Management
Version ManagementVersion Management
Version Management
Keishin Yokomaku
 
イカしたライブラリを作った話
イカしたライブラリを作った話イカしたライブラリを作った話
イカしたライブラリを作った話
Keishin Yokomaku
 
Google I/O 2013 報告会 Android Studio と Gradle
Google I/O 2013 報告会 Android Studio と GradleGoogle I/O 2013 報告会 Android Studio と Gradle
Google I/O 2013 報告会 Android Studio と Gradle
Keishin Yokomaku
 
自己組織化
自己組織化自己組織化
自己組織化
Keishin Yokomaku
 

More from Keishin Yokomaku (14)

UI optimization for night
UI optimization for nightUI optimization for night
UI optimization for night
 
Popup view on Mortar
Popup view on MortarPopup view on Mortar
Popup view on Mortar
 
Regexp in Android and Java
Regexp in Android and JavaRegexp in Android and Java
Regexp in Android and Java
 
Deep Inside Android Hacks
Deep Inside Android HacksDeep Inside Android Hacks
Deep Inside Android Hacks
 
Make it compatible
Make it compatibleMake it compatible
Make it compatible
 
Signature
SignatureSignature
Signature
 
Android Media Hacks
Android Media HacksAndroid Media Hacks
Android Media Hacks
 
Null, the Abyss
Null, the AbyssNull, the Abyss
Null, the Abyss
 
?
??
?
 
Typeface
TypefaceTypeface
Typeface
 
Version Management
Version ManagementVersion Management
Version Management
 
イカしたライブラリを作った話
イカしたライブラリを作った話イカしたライブラリを作った話
イカしたライブラリを作った話
 
Google I/O 2013 報告会 Android Studio と Gradle
Google I/O 2013 報告会 Android Studio と GradleGoogle I/O 2013 報告会 Android Studio と Gradle
Google I/O 2013 報告会 Android Studio と Gradle
 
自己組織化
自己組織化自己組織化
自己組織化
 

Recently uploaded

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
Jen Stirrup
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 

Recently uploaded (20)

LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...The Metaverse and AI: how can decision-makers harness the Metaverse for their...
The Metaverse and AI: how can decision-makers harness the Metaverse for their...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 

Building stable and flexible libraries

  • 1. Building stable and flexible libraries @KeithYokoma - Drivemode, Inc. potatotips #12
  • 2. KeithYokoma Keishin Yokomaku Drivemode, Inc. Android Engineer GitHub: https://github.com/KeithYokoma e-Book: http://amzn.to/1mZNydv
  • 5. Make libraries STABLE • Entity class declaration • Multi-thread compatibility • Lifecycle management
  • 6. Make libraries STABLE • Entity class declaration • Don’t • Do void setToken(String token, String type, String refresh, long by); void setToken(AccessToken token);
  • 7. 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);
  • 8. • Entity class declaration • Easy to remember the type of args • Type-Safe void setToken(AccessToken token); Make libraries STABLE
  • 9. Make libraries STABLE • Multi-thread compatibility • Synchronization • Immutable entity • Thread pool and callback lifecycle • Singleton implementation
  • 10. Make libraries STABLE • Multi-thread compatibility • Synchronization • “synchronized” block • Synchronization utils(CyclicBarrier, …) • Atomicity(AtomicInteger, …) • “volatile” field
  • 11. Make libraries STABLE • Multi-thread compatibility • Immutable entity • Immutable entity is thread safe
  • 12. 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
  • 13. Make libraries STABLE • Multi-thread compatibility • Singleton implementation • Be aware of “Lazy Initialization”
  • 14. // 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
  • 15. Make libraries STABLE • Multi-thread compatibility • Singleton implementation • “synchronized” block • Double checked locking • Initialization on demand holder
  • 16. private static Singleton sInstance; public static synchronized Singleton getInstance() { if (sInstance == null) { sInstance = new Singleton(); } return sInstance; } Case Study Multi-thread compatibility
  • 17. 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
  • 18. static class Holder { public static final Singleton SINGLETON = new Singleton(); } public static getInstance() { return Holder.SINGLETON; } Case Study Multi-thread compatibility
  • 19. Make libraries STABLE • Lifecycle management • Object lifetime alignment
  • 20. Make libraries STABLE • Lifecycle management • Object lifetime alignment • Lifecycle methods of various “Context” • onCreate/onDestroy • onStart/onStop, onResume/onPause
  • 21. Make libraries STABLE • Lifecycle management • Object lifetime alignment • Naming convention • add/remove, register/unregister • start/finish, initialize/destroy
  • 23. Make libraries FLEXIBLE • Annotations vs Listeners • Customizable resources • Split package by domain
  • 24. 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
  • 25. Make libraries FLEXIBLE • Listeners ✓ Faster than annotations(runtime) ✓ Simple architecture ✗ Client should maintain the lifetime
  • 26. Make libraries FLEXIBLE • Annotations and Listeners • Do NOT call methods of dead object
  • 27. • Customizable resources • If the library has UI resources… • Theme should be customizable • What about layout resources? Make libraries FLEXIBLE
  • 28. • Customizable resources • At least you need to… • Define ID resources that the library uses • Otherwise layout may not be customized Make libraries FLEXIBLE
  • 29. Make libraries FLEXIBLE • Split package by domain • Avoid exceeding 65k method limit • Less effort to strip out codes not used
  • 30. 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, …
  • 31. –Joshua Bloch “Never make the client do anything the library can do for the client.”
  • 32. Building stable and flexible libraries @KeithYokoma - Drivemode, Inc. potatotips #12