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 ...

Get Android Design Patterns and Best Practice now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.