Let's say we have global ProductFactory class like this:
global class ProductFactory {
global static ProductService getProductService() {
return new ProductServiceBasic();
}
}
Also there is global ProductService interface (it's located inside ProductFactory class):
global interface ProductService {
List<String> getAllProducts();
List<String> getProductTypes();
}
And finally we have class-implementation of ProductService (as an inner class in in ProductFactory class as well), which is private for now with public methods coming from global interface:
private virtual class ProductServiceBasic implements ProductService {
public List<String> getAllProducts() { ... }
public List<String> getProductTypes() { ... }
}
Now we need to be able to use all of this outside of our package, like this:
Boom.ProductFactory.ProductService service = Boom.ProductFactory.getProductService();
List<String> productTypes = service.getProductTypes();
Question here is: do we need to make global ProductServiceBasic class? do we need to make all methods of this class global as well? It's not quite obvious, since ProductService and ProductFactory are referenced explicitly in this snippet above on subscriber org, but ProductServiceBasic is like an implicit asset which is accessed only via global ProductService interface. In other words, if we want to prevent subscriber from using ProductServiceBasic directly and force them to go only via global ProductService interface, can we keep ProductServiceBasic as private class with just public methods or would the above snippet throw an exception?