O'Reilly logo

Android Design Patterns and Best Practice by Kyle Mew

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A sandwich builder pattern

The builder pattern is purpose-built for combining simple objects to form one complex object, and this forms a perfect analogy of making a sandwich. We encountered a generalized builder pattern earlier in the book, but now we need to adapt it for a specific function. Furthermore, we will be connecting the pattern to a working UI so that a sandwich can be constructed according to user selections rather than the set meal demonstrated in previous builder examples.

Applying the pattern

To keep the code short and simple, we will only create two concrete classes of each ingredient type, and we will use buttons and a text view to display the output rather than a recycler view. Simply follow these steps to create our sandwich ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required