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

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

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