Android Programming The Big Nerd Ranch Guide, 3rd Edition

(Brent) #1

Application Architecture with Fragments


153

Application Architecture with Fragments


Designing your app with fragments the right way is supremely important. Many developers, after first
learning about fragments, try to use them for every reusable component in their application. This is the
wrong way to use fragments.


Fragments are intended to encapsulate major components in a reusable way. A major component in
this case would be on the level of an entire screen of your application. If you have a significant number
of fragments on screen at once, your code will be littered with fragment transactions and unclear
responsibility. A better architectural solution for reuse with smaller components is to extract them into
a custom view (a class that subclasses View or one of its subclasses).


Use fragments responsibly. A good rule of thumb is to have no more than two or three fragments on the
screen at a time (Figure 7.21).


Figure 7.21  Less is more


http://www.ebook3000.com

Free download pdf