Service Provider Structure in java

According to the book “Effecive java”, which makes the statement “ The class of the object returned by the static factory method does not even exist while the class containing the method is written .” Means in the following paragraph:

The class of the object returned by the static factory method does not even exist when the class containing the method is written. Such flexible static factory methods form the basis of service provider infrastructures, such as the Java Connection API (JDBC) database. A service provider framework is a system in which several service providers implement a service, and the system implements implementations available to its customers, separating them from implementations

+4
source share
2 answers

According to the book "Effective java", which makes the statement "Class object returned by the static method factory, there is not even time at which the class containing the method is written." means the following paragraph:

A good way to explain what is meant by this sentence is to look at the type EnumSetthat is the class in the package java.util.

EnumSetis an abstract class without any constructors available. To get an instance EnumSet, the programmer uses one of his static factory methods, for example. EnumSet.of( ... ). For instance:

Set<MyEnum> s = EnumSet.of(MyEnum.FIRST_CONSTANT);

, of(), EnumSet. , MyEnum. MyEnum 64 , , of(), RegularEnumSet. MyClass 64 , JumboEnumSet. . , , - , EnumSet.

, Java , EnumSet, , , ( 1024). , EnumSet :

final CachedEnumSet extends EnumSet {
    :
    :
}

, CachedEnumSet EnumSet, , , Java .

, EnumSet.of(), RegularEnumSet, JumboEnumSet CachedEnumSet, , , , EnumSet .

+6

factory, , , ( , ). , , . factory.

. JDBC - - DriverManager - URL- . URL- DriverManager , . Oracle, Oracle ( API JDBC), , DriverManager Oracle .

, , factory AA. factory , , . CLASSPATH. factory , , factory.

, : JDBC, , XML.

+1

Source: https://habr.com/ru/post/1658612/


All Articles