Creational_Abstract Factory
â Abstract Factory
- similar to factory,
- but with a focus on the client
add
clientto factory pattern- interface creates the related classes instance
- đđť can hide which
concrete productto the client
â Diagram
đ ShipFactory example
Factory đ AbstractFactory
- ęłľíľě : make creation of instance abstract with instance
- Factory: hide the creation of instance in concrete factory
- focus more on how to implement factory, interitance
- move instance creation process to concrte factory class
- đđť defines an interface for creating an object, but lets subclasses (or a factory class) decide which class to instantiate
- AbstractFactory: client does not have to see the concrete factory
- foducs more on how to use factory, composition
- create related instances without relying on a concrete class
- đđť interface for creating families of related objects without specifying their concrete classes.
đ ď¸
- in
javax.xml.parsers DocumentBuilderFatoryto create xml
1
2
3
4
5
6
public static void main(String[[ args) throws ParserConfigurationException, IOException, SAXException{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new File("src/main/resource/config.xml"));
System.out.println(document.getDocumentElement());
}
FactoryBean<T>
This post is licensed under CC BY 4.0 by the author.

