
016: Effective Java for Android developers : Item 2
About this episode
In our third Fragment installment, we introduce Josh's second Item: Consider a builder when faced with many constructor parameters.
Stay tuned for more items from our "Effective Java for Android developers" Fragment series.
[audio src="http://traffic.libsyn.com/fragmented/ep_14_fragmented.mp3" preload="none" autoplay="false"]
[Download][1]
Show Notes
Consider a builder when faced with many constructor parameters
Patterns available for constructing object with parameters:
- Telescoping Constructor Pattern - Provideconstructor with only required parameters, another with a single optional param, a third with 2 optional params... and so on.
- Advantage: Works well for small number of parameters
- Disadvantage: Does NOT scale well
- JavaBeans Pattern - Callparameterless constructor to create the object; then call setter methods to set required parameter and each optional param of interest.
- Advantage: Scales well, easy (but wordy) to read resulting code
- Disadvantage: Allows inconsistency (if all required params not called); impossible to make classes immutable if using this pattern.
- Builder pattern - winner!
- Advantage: Simulates named optional parameters; allows immutable objects to be constructed; flexible
- Disadvantage: more ceremony to actually construct the Builder Class and finally use.
Example usage from Android source:
- AlertDialog Builder [androidxref.com]
Tip:
Contact us:
- @fragmentedcast [twitter.com]
- @donnfelker [twitter.com]
- @kaushikgopal [twitter.com]
Get every episode summarized
Each time Fragmented - AI Developer Podcast publishes, we email you a written briefing from the transcript — the topics, who appeared, and any specific claims, with the ad reads skipped.
Email me new episodesFree for 3 shows. No card needed.
Hosts & guests
No transcript yet
This episode has not been transcribed. Request it and it moves to the front of the queue.
More episodes
More from Fragmented - AI Developer Podcast

311 - Self learning harnesses are here
Fragmented - AI Developer Podcast

310 - Mitchell Hashimoto on Ghostty & His Agentic Coding Workflow
Fragmented - AI Developer Podcast

309 - Background Agents
Fragmented - AI Developer Podcast

308 - How Image Diffusion Models Work - the 20 minute explainer
Fragmented - AI Developer Podcast