One of the design patterns: simple factory models

Source: Internet
Author: User
Tags flock

One of the design patterns: simple factory models

In the past few days, I have prepared to take a good look at the design model. As a result, I have taken some notes and read some of the design patterns separately. I have also used or met some design patterns during project development, however, it may only be a bit of an impression on the design model, and sometimes the name is mixed up. I hope this opportunity for system learning will make me more impressed with the design model.
The main reference materials for this study and design model include:
Big talk Design Model
Http://www.dofactory.com/net/design-patterns
Both of the above are implemented in C #, but I am going to use C ++ code to implement it again, so that I can gain a deeper impression on C ++.
First, start with the simplest simple factory model.
First, the UML diagram:

It mainly includes:

AbstractProduct: Abstract Product. It is the parent class of all products and is actually an interface. ConcreteProduct: a specific Product. In fact, the code that implements the logic is defined in a specific Product by several ConcreteProduct types. SimpleFactZ restart? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> flock + flock/bL6yfqyu82stcRQcm9kdWN0oaMNCjxwPs/Cw + flock =" brush: java; "> # Include # Include # Include /* Simple engineering mode */class AbstractProduct {public: virtual void getResult () = 0 ;}; class ConcreteProductA: public AbstractProduct {public: void getResult () {std :: cout <"ConcreteProductA: getResult ()" < GetResult (); SimpleFactory: createProduct ('B')-> getResult (); SimpleFactory: createProduct ('C')-> getResult (); return 0 ;}

The execution result is as follows:

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.