FAU Android

FAU's local android experts!

Patterns and Refactoring in Android

Posted by Mihai April - 13 - 2010 - Tuesday Comments Off

In order to have high quality frameworks developed as part of their class projects, students were exposed to concepts such as patterns and refactoring. Although you could have an entire course on these subjects, we tried to compress the basic ideas into two lectures.

Patterns are a general and flexible way of solving a recurrent problem. The principles behind patterns are described in Bruce Eckel’s Thinking in Patterns book. In a nutshell:

  • A design is finished when you cannot take anything away from it
  • Duplication should be avoided
  • Occam’s razor: the simplest solution is the best

There are different types of patterns. Students were presented architectural patterns, such as Model-View-Controller (MVC), and Design Patterns (such as Factory method, Builder, Strategy).

For each of the patterns, a short description of it (in terms of its components, features, and principles behind it), together with an example written in Android were shown.

Refactoring is about “a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior”, as mentioned in Refactoring: Improving the Design of Existing Code, by┬áMartin Fowler, Kent Beck, John Brant, William Opdyke, Don Roberts. ┬áThe class presentation and code were based on this book. We covered reasons for refactoring your code (like improving the design of the software, make it easier to understand, helps in finding bugs an develop code faster), and when one should consider refactoring (when adding a function, fixing a bug, etc). In addition, use cases of when and how were shown, such as when having duplicate code, or a long method/class/parameter list. Students were taken step by step through the process of applying refactoring methodologies (like extracting method, extracting class, replace parameter list with object, etc) in those cases.