search
HomeJavaJavagetting StartedThe difference between abstract factory pattern and factory method pattern in java

The difference between abstract factory pattern and factory method pattern in java

Nov 15, 2019 pm 04:01 PM
javathe differenceFactory method pattern

The difference between abstract factory pattern and factory method pattern in java

1. Simple factory pattern

Features:

1. It is a specific Class, non-interface abstract class. There is an important create() method, which uses if or switch to create a product and return it.

2. The create() method is usually static, so it is also called a static factory.

Disadvantages:

1. Poor scalability (I want to add a kind of noodles. In addition to adding a new noodle product class, I also need to modify the factory class method).

2. It is not supported when different products require different additional parameters.

2. Factory method pattern

Pattern description:

Provides an interface for creating objects (factory interface) , let its implementation class (factory implementation class) decide which class (product class) to instantiate, and the implementation class creates instances of the corresponding class.

ModelForm elements:

Provide a product class interface. All product classes must implement this interface (it can also be an abstract class, that is, an abstract product).

Provide a factory class interface. All factory classes must implement this interface (ie, abstract factory).

Instances of the product class are created by the factory implementation class. The factory implementation class should have a method to instantiate the product class.

3. Abstract Factory Pattern

Pattern description:

To create a group of related or Interdependent objects provide an interface without specifying their concrete classes.

4. Difference

The abstract factory pattern is an upgraded version of the factory method pattern. It is used to create a set of related or interdependent objects.

The difference between it and the factory method pattern is that the factory method pattern targets a product hierarchical structure; while the abstract factory pattern targets multiple product hierarchical structures.

In programming, usually a product structure is represented by an interface or abstract class. That is to say, all products provided by the factory method pattern are derived from the same interface or abstract class, and the abstract factory pattern The products provided are derived from different interfaces or abstract classes.

In the abstract factory pattern, there is a concept of product family: the so-called product family refers to a family of functionally related products located in different product hierarchical structures. The series of products provided by the abstract factory pattern form a product family; while the series of products provided by the factory method are called a hierarchical structure.

Recommended tutorial: Java tutorial

The above is the detailed content of The difference between abstract factory pattern and factory method pattern in java. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)