Applying a builder pattern

The builder design pattern is one of the most useful creational patterns as it builds larger objects from smaller ones. This is precisely what we want to do to construct a sandwich object from a list of ingredients. The builder pattern has a further advantage in that optional features are easy to include later. As before, we will begin by creating an interface; we will call it Ingredient and use it to represent both bread and filling. This time, we will need to represent calories as an integer, as we will need to calculate the total amount in a finished sandwich.

Open an Android Studio project, or start a new one, and follow the proceeding steps to create a basic sandwich builder pattern:

  1. Create a new interface called ...

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.