Skip to content

Instantly share code, notes, and snippets.

@sgzsh269
Last active April 3, 2017 19:13
Show Gist options
  • Save sgzsh269/a437ec36bc867c349fb55e284ed350f9 to your computer and use it in GitHub Desktop.
Save sgzsh269/a437ec36bc867c349fb55e284ed350f9 to your computer and use it in GitHub Desktop.
/*
Sample problematic Activity to illustrate sub-optimal architecture
This Activity has the following issues:-
1. The Activity contains business logic to fetch, filter and transform data thus
making it difficult to test business logic in isolation as it requires the
Activity and views to function.
2. The Activity and its Views cannot be tested in isolation as it requires the
API and business logic for data.
3. Overtime, since the Activity also hosts business logic, with new features
or enhancements, it can get difficult to manage changes as there will be
no logical seperation of code. Also with little to no regression testing,
it will be difficult to make changes confidently.
*/
public class ProblematicActivity extends AppCompatActivity {
ImageView imageView;
TextView textView;
ApiClient apiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
getData();
}
private void getData() {
apiClient.getData(new Callback() {
@Override
public void onSuccess(Response response) {
Data data = Data.parse(response)
Data filtered = filter(data);
Data transformed = transform(filtered);
imageView.setImageBitmap(data.bitmap);
textView.setText(data.text);
}
@Override
public void onFailure(Throwable throwable) {
Toast.make(this, "Error", Toast.LENGTH_LONG).show();
}
});
}
private Data filter() {...}
private Data transform() {...}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment