The Builder pattern

You may have noticed the usage of the Builder pattern when we added parameters to the AlertDialog we created in the ReviewCriteria class. If you are not familiar with this approach, basically each of the methods invoked, such as AlertDia-log.setMessage() and AlertDialog.setTitle(), returns a reference to itself (this), which means we can continue chaining method calls. This avoids either an extra-long constructor with many parameters or the repetition of the class reference throughout the code. Intents make use of this handy pattern too; it is something you will see time and time again in Android.

take a closer look at the all-important Android Activity lifecycle and how it relates to processes on the platform.

0 0

Post a comment