bin^2

bin^2

discord server
twitter

How I Develop Android Apps - Package Structure

How I Develop Android Apps - Package Structure#

#article/done/published
#2021-01-17

Package Naming Rules#

namespace com.company.project {
	namespace framework{
		namespace common{}
		namespace services{}
	}
	namespace features {
		namespace feature_a {
			namespace module_aa {
				namespace ui {
				
				}
				namespace core {
				
				}
				namespace data {
				
				}
				com.company.project.features.feature_a.module_aa.ui-->com.company.project.features.feature_a.module_aa.core
				com.company.project.features.feature_a.module_aa.data-->com.company.project.features.feature_a.module_aa.core
			}
			namespace module_ab {
				namespace ui {
				
				}
				com.company.project.features.feature_a.module_ab.ui --> com.company.project.features.feature_a.module_aa.core
			}
		}
		namespace feature_b {
			namespace module_ba {
				namespace ui {
				
				}
				com.company.project.features.feature_b.module_ba.ui --> com.company.project.framework.services
				com.company.project.features.feature_a.module_ab.ui --|> com.company.project.framework.services

			}
		}
		namespace feature_n {
			namespace module_na {
			
			}
		}
	}
	namespace app{
		
	}
	com.company.project.app --> com.company.project.features
	com.company.project.app --> com.company.project.framework
}

com.{company}.{project}.{layer}.{feature}.{module}.{usage}
layer=app|features|framework
feature=feature1|feature2|...
module=module1|module2|...
usage=ui|data|core|....

company is the company name, and project is the project name.
layer represents the layers.
app is the shell project used to integrate core features (features) and infrastructure (framework).

package com.company.project {
	package app{
	
	}
	package framework{
	
	}
	package features{
	
	}
	features --> framework
	app --> features
}

features contains packages for various features.

package features{
	package feature_a
	package feature_b
	package feature_n
}

Each feature contains one or more modules, and the feature is deployed and integrated as a component.

package feature_a{
	package module_aa
	package module_ab
}

The usage in each module represents the layers within the module.

package module_aa{
	package ui{
	
	}
	package data{
	
	}
	
	package core{
	
	}
	ui-->core
	data -->core
}

The ui|data|core in the module are not necessarily all present. There can be only one or two or all of them.
In the actual development process, some modules have interfaces, while others only have data.

package features.feature_a{
package module_ac{
	package ui
	package core
	package data
	data--|>core
	ui-->core
}
package module_aa.ui
package module_ab.ui
module_aa.ui --> core
module_ab.ui --> core
}

The ui follows the MVVM pattern and is divided according to the interface, placed in the pages package.
The utils package contains utility classes that are not specific to a particular page but are applicable to all pages.
The usecases package contains data processing logic that can be reused between different pages.

package ui{
	package usecases
	package pages{
		package page_a{
		
		}
		package page_b{
		
		}
	}
	package utils 
	page_a --> utils
	page_b --> utils
	page_a --> usecases
	page_b --> usecases
}

In the core package, it is divided into domains based on the domain.
The usecases package contains the implementations of usecases used in the ui.
In each domain, entities that are independent of specific technology frameworks are obtained through the Repository. The implementation of the repository and entity is in the data package.

package core{
	package usecases{
		class SampleUseCase
		SampleUseCase --> domain_a
		SampleUseCase --> domain_b
	}
	package domain_a{
		class DomainAEntity
		interface IDomainARepository
		IDomainARepository-->DomainAEntity
	}
	package domain_b{
		class DomainBEntity
		interface IDomainBRepository
		IDomainBRepository-->DomainBEntity
	}
	package utils {
	
	}
	usecases --> utils
	domain_a --> utils
	domain_b --> utils
}

The data layer is divided based on the storage method, such as api/room/datastore.
The repositories package contains the implementations of the repository interfaces in the core package. The repository is also responsible for implementing caching.
The utils package contains utility classes.

package data{
	package api
	package room
	package datastore
	package repositories
	package utils
	

}

Reference#

[[How to Use Namespaces]]

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.