What is the purpose or idea of instantiating this class in an abstract class?

I read the LogFactory.class source code in JDK.
LogFactory.class declares an abstract class LogFactory. There is a static attribute in the source code, and the code related to this attribute is as follows:

public abstract class LogFactory{
    //
    //...
    
    static LogFactory logFactory = new SLF4JLogFactory();
    
    //
    //...
}

where the class SLF4JLofFactory is a subclass of the abstract class LogFactory. The above code overrides abstract methods in the abstract class LogFactory by transforming upwards.
my question is, what is the purpose of declaring an attribute of a static LogFactory class in the abstract class LogFactory? What is the purpose or idea of instantiating this class in an abstract class?

Jun.19,2021

if you guess correctly, this should not be the source code of JDK, but the source code of the bridge package between JCL and SLF4J

both JCL and SLF4J only provide interfaces for logging. The real implementation is provided by the logging components you use, such as logback or log4j

.

most projects directly use a unified logging interface to record logs, which makes it convenient for developers to choose their favorite logging components

the role of your source code is to bridge JCL and SLF4J, to put it simply: if your project (including the libraries you use, or framework) uses both JCL and SLF4J, but you want to unify the logs, all use one component, then you need to bridge JCL and SLF4J.

use static and instantiate this class to implement singletons, you should only need a factory.

as a bridge, you only need to implement some methods, so use abstract classes.

The idea of

is the basic

of the principles of object-oriented design.

it is recommended that you read material 1. Design pattern data 2. Log component

Menu