Careeroza
Real World Example
Organising a Food Delivery Backend
A Zomato-like backend is organised by feature. Each feature package exposes a small public service and hides helpers.
com.fooddelivery ├── restaurant RestaurantService (public), MenuParser (package-private) ├── order OrderService (public), OrderValidator (package-private) ├── delivery DeliveryService (public), RouteCalculator (package-private) └── common Money, AppException
package com.fooddelivery.order;
import com.fooddelivery.common.AppException;
import com.fooddelivery.common.Money;
import com.fooddelivery.restaurant.RestaurantService;
import java.util.List;
public class OrderService {
private final RestaurantService restaurants;
private final OrderValidator validator = new OrderValidator(); // same package
public OrderService(RestaurantService restaurants) {
this.restaurants = restaurants;
}
public Money place(String restaurantId, List<String> itemIds) {
if (!restaurants.isOpen(restaurantId)) {
throw new AppException("Restaurant is closed");
}
validator.validate(itemIds);
return restaurants.priceOf(restaurantId, itemIds);
}
}