Design Pattern abstract factory pattern read, design pattern factory read
Original article address: Abstract Factory Mode
Abstract Factory models are the ultimate form of factory-related models.
Definition: provides an interface for creating a group of related or interdependent objects without specifying their specific classes.
The difference from the factory model is that the factory also has an interface specification.
There is a non-obvious Abstract Factory mode in the jdk source code:
- That is, the List interface, which is based on the iterable, expands a method for creating a product.
- The iterator () and listIterator () are different functions although the latter is a subclass of the former.
- Iterator is an Iterator that can only move backward.
- ListIerator is an iterator capable of moving forward and backward.
- Therefore, the two products should be different.
This figure shows the relationship between them.
Here I can only say this picture is really good.
- The List Abstract Factory role has two products, iterator and listIterator. It is recommended that you refer to the source code and see the figure. The specific implementation of these two iterators is internal.
- Iterator and listIteratot are equivalent to the two product specifications (Abstract products). This ignores the inheritance of listiterator and iterator. The implementation of iterator is abstractlist. the implementation of itr and listIterator has two implementations, ignoring the abs. itr and abs. listitr relationship
- The relationship in this figure can be roughly described as follows:
- Abstract Factory List
- Factory Implementation of ArrayList
- Product specifications Iterator ListIterator
- Specific product AbstractList. Itr (see Figure products are not necessarily symmetric), listing list. Itr, listing list. ListIter
Summary:
- Simple factory, no abstract simple factory, against the principle of opening and closing
- Factory model, abstract factory, abstract product, but only one series of products can be created
- Abstract Factory model with multiple product lines
Although it seems that the factory model is relatively simple, but most people did not think about this problem during development, I did not think about it, so please hurry up.