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: