Android DTT #22 — Split Code Into Modules

How to structure the module?

I’d suggest that you split the code into modules by feature first, not by layer. So for an e-commerce app you’d probably have: app, core, checkout, user, and search.

// inside checkout-publicpublic interface CheckoutService {
void goToCheckout(SelectedGoods selectedGoods);
}
// code inside checkout modulepublic class CheckoutServiceImpl implements CheckoutService {
@Override
public void goToCheckout(SelectedGoods selectedGoods) {
// goto activity, call API, etc
}
}
// code inside search module// Use DI such as dagger. Construct the dependency graph in the top // level module (app)
@Inject
private CheckoutService checkoutService;

public void onCheckoutButtonClick() {
checkoutService.goToCheckout(getSelectedGoods());
}

--

--

Android Engineer. I'm all into mobile apps.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ahmad Fadli Basyari

Ahmad Fadli Basyari

Android Engineer. I'm all into mobile apps.