Both, the creator as well as the product, in both instances of the pattern are abstract classes. Both factory classes have a static method called newInstance that returns an instance of the Factory. The concrete class chosen for instantiating depends on the system properties. Once an application has obtained a reference to a factory, it can use it to configure and obtain parser instances.
A number XML parsing API's are available in for java. You can install any of them with your jdk. Each one of them would have provided concrete implementations of the creator and product classes. For example, on my system this code gives the following output.
import javax.xml.parsers.*;
public class FactoryTest{ public static void main(String args[]) throws Exception{ SAXParserFactory parserFactory = SAXParserFactory.newInstance(); SAXParser parser = parserFactory.newSAXParser(); System.out.println("Creator: "+parserFactory.getClass()); System.out.println("Product: "+parser.getClass());
Output: Creator: class com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl Product: class com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl Creator: class com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImp l Product: class com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl
I think the designers of the java have provided hooks that the vendor specific sub-classes to fill in.
Can the knowledgeable members of the forum throw some more light as to why Factory method pattern is used here?