Design Pattern abstract factory pattern read, design pattern factory read

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.