Skip to content

Principles

Hadi Mehrpouya edited this page Jan 26, 2025 · 9 revisions

Principles of good app design

Android App architecture shares many good practices with Object Oriented Programming principles.

The four main principles of object-oriented programming (abstraction, inheritance, encapsulation, and polymorphism). The core principle is abstraction. Without it, the others couldn't exist. Source

Your app is in mercy of Android OS and your users: Android OS may decide to kill your app to make space for other active apps, the user might minimise, kill your app. This means you should really think about how you are going to store data and your components should be developed in a way that they are independent from each other. You need to always remember this, because the environment is not in your control, so your app should be able to deal with any of the situations above.

Make your Apps SOLID

SOLID stands for:

  1. Seperation of concerns
  2. Open-Closed
  3. Liskov Substitution
  4. Interface Segregation
  5. Dependency Inversion

Seperation of concerns

Writing code in hacky way is easier at first instead of figuring out how to do something properly. It's easy to mistakingly write all your code in an activity or a fragment. Seperation Of Concerns (SOC) is a priciple that attepts to do the opposite, to have independant and smaller components.

Activities and Fragments are meant to be used to represent data and deal with Android OS state changes.

You can design you app following this principle by encapsulating information inside a section of code with a well-defined interface. Encapsulation is a means of information hiding. In Android we use Layered design in information systems. This means seperating apps into (e.g., presentation layer, business logic layer, data access layer, persistence layer).

To acheive this seperation we develop models for dealing with data seperated from UI components, this means if anything happens to the app, the data stays safe. Data models should also be able to deal with unrelaiable internet connection.

3 Liskov Substitution Principle (LSP):

introduced by Barbara Liskov in a 1987 conference keynote address titled Data abstraction and hierarchy. It is based on the concept of "substitutability"

LSP is a principle in object-oriented programming that states that objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program.

Dependency injection best practices

Clone this wiki locally