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.