I am in the middle of reading Chapter 12 the classes PizzaFragment, PastaFragment, and StoresFragment (pages 486, 487, and 488) look almost identical. The only difference is the String Array Resource (R.array.pizzas, R.array.pasta, and R.array.stores).
Could a more general class be used where a is String array is passed into the constructor? Is that something that I a missing in the Android architecture that would prevent this? or was it just simpler to create three classes, when the objective of the section was to describe pagers?
Good question The code is designed to be understandable, not to be efficient, so in a real application you would most certainly look for efficiencies and to remove duplication. But for the purposes of teaching, we will often leave duplications in place, if it leaves the code easier to understand.
Head First Android Development
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop