7

I believe the Template method pattern involves encapsulating each step in the algorithm.

I think activity's life cycles (onCreate, onResume, etc) are steps that must be overridden by the concrete class.

Does this mean that the Android activity lifecycle (activity and fragment classes) conform to the template design pattern or is there a different pattern which suits it better

Thanks

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
ShakeJ
  • 633
  • 5
  • 10
  • If it helps you to think of it that way, then sure. – Karakuri Sep 16 '14 at 01:28
  • I just had the same question in mind. And studying the Android lifecycle API, I'm pretty sure it it is template method desing pattern. – Dude Feb 27 '15 at 23:05

1 Answers1

2

The way Android framework is built is definitely following the template pattern, which is its strength but also its weakness. Because this pattern suggests to implement only some part of the module, it gets pretty easy to obtain a quick and simple result without involving too many efforts.

However, as its is based on inheritance, this can get really nasty once you start thinking about extending the framework, or deal with cross-concerns pattern. Most of android framework require to extend an Activity in order to be used, and as multi-inheritance is not an option, this limits the way you can compose your features.

An approach that favors composition over inheritance would have been more than welcome, and the only reason I can imagine why this choice has been made is performance problems.

Francis Toth
  • 1,595
  • 1
  • 11
  • 23