Follow examples to learn design patterns-the difference between factory methods and abstract factories

Source: Internet
Author: User

Factory methods and abstract factories are all part of the factory model, so what is the difference between them? Let's compare them.

First we analyze from the point of view of the factory interface.

Factory Method:

The factory method is to create interfaces for creating different functions of a product, and returns the same output from products that classify different functions. For example, the manufacture of automotive engines can be used in factory methods, and the engines are divided into direct-injection engines and turbo-charged engines.

Abstract Factory:

Abstract Factory is to create a cascade of products, such as automobiles, cars by the engine, fuel tanks, tires and so on, then a product is a number of related products and can be divided into series (trucks, cars, sports cars) products can be used in the abstract factory to achieve, Each plant is a product that is created with some dependent products (creating engines, creating tanks).

Next we analyze from the perspective of the products created:

The product created by the factory method is a layer, not a constituent relationship. For example: engine, or addition, subtraction, multiplication, etc.

The products created by the abstract factory are multi-layered, and there may be dependencies between tiers. For example: Cars from trucks, cars, sports cars, such as abstract, the car by the engine, fuel tank, tires and other components, such as: access to different databases, the database has MySQL, SQL Server points, MySQL has user tables, Department table.

The above analysis may be very simple, I hope you can write about these two patterns, from which you may realize their differences.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Follow examples to learn design patterns-the difference between factory methods and abstract factories

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.