IOS design model learning (5) Abstract Factory

Source: Internet
Author: User

1 Preface
The abstract factory provides an interface for creating a series of associated or interdependent objects without specifying their specific classes or their creation details. There is no coupling between the client and the specific object obtained from the factory.

2. Details
2.1 Brief Introduction
The Client only knows about AbstractFactory and AbstractProduct. In each factory class, the structure and actual operation details are treated in black box. Even products do not know who will be responsible for creating them. Only the specific factory knows what to create for the client and how to create it. This mode is often implemented in the factory mode. The factory method delays the actual creation process to the subclass that reloads it.

Abstract Factory mode is often used together with other design modes such as prototype, Singleton mode, and exclusive metadata mode.

2.2 differences between Abstract Factory and factory methods
Abstract Factory:

(1) creating abstract products through object combinations;

(2) create multiple products;

(3) You must modify the interface of the parent class to support the new product.

Factory method:

(1) create a product through class inheritance;

(2) create a product;

(3) subclass the creator and reload the factory method to create a new product.

2.3 class clusters
A class cluster is a common design mode in the basic framework, based on the idea of abstract factory mode. It aggregates several related private factory sub-classes to the abstract superclasses of a worker. For example, a number contains a complete set of various numeric types, such as characters, integers, floating-point numbers, and double-precision numbers. These numeric types are the numbers themselves. Therefore, NSNumber naturally becomes the super-type of these subsets ).

A class cluster is a form of abstract factory. For example, NSNumber is a highly abstract factory, while NSCFBoolean and NSCFNumber are factory subclasses.

2.4 compare abstract factories and factories again
Abstract Factory is the abstract factory type shared by multiple specific factory types. Aside from the word "abstraction", "Factory" usually refers to a "specific" factory, and it does not mean a factory method.

Sometimes, a specific factory is used in the design at the beginning, and then reconstructed into an abstract factory that uses multiple specific factories.

3 conclusion
The above is all content and I hope it will help you.

 

Related Article

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.