How to classify android packages

Asked 1 years ago, Updated 1 years ago, 96 views

What criteria do you break down when you classify classes into normal packages on Android?

Until now,

activity.By screen.oooActivity

fragment.by screen.oooFragmemnt

view.oooView

util.oooUtil

adapter.oooAdapter

It was just being used in this way, but it's a random structure, so I'm going to change it properly this time. So I'm leaving a question because I'm curious about how other people normally pack.

Thank you.

android java packaging

2022-09-22 10:47

1 Answers

I used to package by screen or function (1) until the third project, and now I package by component (2) such as activity and fragment.

The method (1) made it easier for new people to understand the structure of the project. However, as the number of screens and functions increased, the number of packages increased too much, making it difficult to manage. I was worried about which package to belong to the class whose functions are not clearly distinguished. Especially when I tried to recycle one fragment or view from another package, I felt very uncomfortable.

The (2) method eliminates the need to think about which package to belong to which class with ambiguous functionality or screen distinction. It doesn't feel uncomfortable even if you recycle it. It's the file I'm looking for. I can find it with quick file search (Cmd+Shift+O) anyway, so it wasn't difficult to find it without dividing the package by function or screen. The longer the project development period, the more comfortable it felt. If there is a disadvantage, there may be several classes used elsewhere while performing similar functions in one package, but I had to name them well. For example, ProductListInMainAdapter, ProductListInSearchAdapter.


2022-09-22 10:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.