The static factory method returns the class to which the object belongs, and can not be present when writing a class that contains the static factory method. This flexible, static factory approach forms the basis of the service provider Framework (Provider framework), such as the JDBC API. The service provider framework refers to a system in which multiple service providers implement a service (interface) that provides multiple implementations of the service provider's clients and decouples them from multiple implementations.
There are four important components in the service provider framework:
- Service Interface, which is implemented by the provider. such as the connection of JDBC
- Provider Registration API (Provider Registration API), which is used by the system to register provider implementations that allow clients to access them. such as Drivermanager.registerdriver
- The Services Access API (service Access API) is the instance that the client uses to obtain the service. such as Drivermanager.get
- Service Provider Interface (Provider Interface) These providers are responsible for creating instances of their service implementations. This is optional. such as driver
If there is no service provider interface, the implementation is registered according to the class name and instantiated by reflection. The interface is superior to the reflection mechanism and is strongly recommended for use with the service provider interface.
"Effective Java" service provider framework