{Google Developer Group Sonargaon}
2023
Builder Design Pattern
Android Development Perspective
Who I am?
Hasan Abdullah
Currently Contributing in
Muslims Day
Few Previous Client Projects
Let’s start!
Think about a complex object creation.
Example of a constructor with long parameters
Too many parameters
Understanding the problems
Immutability
Telescopic constructors
Order of initialization
Problem: Telescopic Constructor
Multiple network configurations like time out, cache size, retry mechanism etc should be immutable
Where the size and margin of the canvas should be unchangeable. Other painting properties should not be changed again and again
Network Config
Painting on Canvas
notification title, subtitle, icon etc should not be changed after object creation. These properties should be fixed
Notification config
Problem: Immutability
Examples
From animation execution, the order of execution is important.
First of all we need to set the size of the canvas. Background color, margin of the canvas. Then the other objects will be painted.
Animation properties
Painting on canvas
We need to set the title section first. Then the rest of content
Document Builder
Problem: Order of initialization
Examples
What is the solution?
Solution is
Builder Design Pattern
What should we support?
User’s expectations
Builder Pattern Implementation
Few common uses of
Builder Pattern in Android
Ex: Glide Image Loader Library
Ex: Notification Builder
Ex: Retrofit Builder
Thank You
Hasan Abdullah
Technical Lead, Brain Station 23 Ltd