我的项目中有以下包和类结构,
package de.mycompany.jakarta.order;
import de.mycompany.ordermanagement.order.OrderCancellationService;
public class DrugOrderManager {
private static final DrugOrderManager INSTANCE = new DrugOrderManager();
private DrugOrderManager() {
}
public static DrugOrderManager getInstance() {
return INSTANCE;
}
public void cancelOrder() {
OrderCancellationService.getInstance().process();
} }
package de.mycompany.ordermanagement.order;
public class OrderCancellationService {
private static OrderCancellationService INSTANCE = new OrderCancellationService();
private OrderCancellationService() {
}
public static OrderCancellationService getInstance() {
return INSTANCE;
}
public void process() {
} }
我的意图是 OrderCancellationService 应该只由 DrugOrderManager 调用,任何其他类/服务都不应该直接调用它。我正在尝试将 DrugOrderManager 作为所有服务的网关。如何限制这种可见性?请指教