DEV Community

Areeba Farooq
Areeba Farooq

Posted on

Common architectural principles

[Android] [AndroidDevelopment]

1) Separation of concerns:

A common mistake is to write all your code in an Activity or a Fragment.These UI-based classes should only contain logic that handles UI and operating system interactions.

Image description

You don’t own implementations of Activity and Fragment.
The OS can destroy them at any time based on user interactions or because of system conditions like low memory. It’s best to minimize your dependency on them.

2) Drive UI from data models:

Data models represent the data of an app. They are independent of the UI elements and other components in your app. This means that they are not tied to the UI and app component lifecycle.

Image description

Persistent models are ideal for the following reasons:

  • Your users don’t lose data if the Android OS destroys your app to free up resources.

  • Your app continues to work in cases when a network connection is flaky or not available.

If you base your app architecture on data model classes, you make your app more testable and robust.

Top comments (0)