From: http://blog.csdn.net/ericzhong83/article/details/7604728 factory method Mode (Factory pattern):Defines an interface to create an object, but subclasses decide which of the classes to instantiate, that is, to create objects from subclasses.Principle:To rely on abstraction, do not rely on specific classes.Case:First explain what the factory is:If you open a pizza shop (Pizzastore abstract class) sell various flavors of
, looks directly the code!
Code:
1 /* ***********************************************
2 Author: xiaowuga
3 Created Time: Monday, October 02, 2017 12:09:34
4 File Name: A.cpp
5 ************************************************ * /
6 #include
View CodeC. Ordering Pizza
Title: Give N and S, say there are now n people, each pizza has s block, now give each person want to eat
interface used in it and the specific implementation
/**
* Description: Raw, cheese */public
interface Cheese {
}
public class Reggianocheese implements Cheese {
}
/**
raw Material, clam */public
interface Clams {
}
public class Freshclams implements clams {
}
/**
* Description: Raw material, dough */public
interface Dough {
}
public class Thincrustdough implements dough {
}
/**
* Description: raw materials, vegetables */public
interface Veggies {
}
pub
Factory mode:Defines an interface for creating an object, but its subclasses determine which object to instantiate. The factory method defers instantiation of an object to a subclass.Pattern Composition:
A group of users: The parent class defines an interface for creating objects and other common interfaces, and subclasses are responsible for creating specific implementations of object interfaces (in the case Pizzastore and Nypizzastore)
A set of product classes: (in the case of the
implementation.
The test procedure is as follows:
Report zbo_dp_004_re.
* Factory method pattern used interface and class
Include zbo_dp_004_if_cl.
* This data used to create two type of concrete creator
Data:
Ny_ref type ref to pizzastore,
Chi_ref type ref to pizzastore.
* The different pizza have the same interface
Data:
Pz_ref type ref to pizza.
Start-of-selection.
* Create two different pizzastore
Crea
05 _ factory mode, 05 factory Mode
Factory Model
1. Simple Factory: another class or object is usually used to encapsulate the instantiation operation.
2. Factory mode: The real factory mode is to define an abstract factory method and postpone the Instantiation to the subclass! (Interfaces play a key role !)
Here is a simple example to illustrate how to use the factory model: Suppose you need to open several Pizza stores. Each
Simple factory mode:You can create multiple types of products based on the input parameter type.There is only one Creator method, which is used to create different products. The input parameter type is used to determine the product to be created, which is easy to implement. However, if you need to expand the product, you need to modify the implementation of the Creator method.There is a Pizza store that can produce different types of
1. PrefaceIn this blog post, we will learn how to query the data in MongoDB. When we store the data in MongoDB, we need to query the data. After all, the query operation in the crud operation is our most frequently used operation in our system. We need to deal with different business needs and construct appropriate query criteria to query the data we want. We need to learn about the syntax and functionality that MONGODB provides to us about queries. Here, we use MongoDB's own MONGO shell (MONGO
CodeForces 151 B struct sorting.The E-struct is coming again.Time Limit:2000 MSMemory Limit:262144KB64bit IO Format:% I64d % I64uSubmit Status Practice CodeForces 151B
Description
Winters are just damn freezing cold in Nvodsk! That's why a groupNFriends prefers to take a taxi, order a pizza and call girls. the phone numbers in the city consist of three pairs of digits (for example, 12-34-56 ). each friend has a phonebook of sizeSI(That's the number o
This system, feel refreshing, believe in more practice, think more, will be familiar with.http://www.jianshu.com/p/2450b785c329#!/usr/bin/evn python#Coding:utf8classPizza (object):defPrepare (self, type):Print 'Prepare {type} pizza'. Format (type=type)defBake (self, type):Print 'Bake {type} pizza'. Format (type=type)defCut (self, type):Print 'cut {type} pizza'. F
includes defining components, including interfaces for assembling these components into a final product.
When creating complex objects (the building sequence between these objects is usually stable), the algorithms should be independent of the components of the objects and their assembly methods;
When the constructor must allow different representations of the constructed object.
[3] How to Use Java to implement this mode
The following is a simple example to show this mode
the project must be optimized.
The starting point for database design is simple. Customer to place the order. Orders include one or more pizzas (at this point, ignoring the possibility of selling other foods). Pizza with a topping or a variety of toppings, you can press half a piece or a whole pizza to put the toppings.
Create a Customer table
Now, you just need to be concerned about getting enough custome
4-1 Pizza:Think of at least three of your favorite pizzas, store their names in a list, and use the For loop to print out the name of each pizza.
Modify the For loop so that it prints a sentence that contains the name of the pizza, not just the name of the pizza. For each pizza, a line of output, such as "I li
E- The structure is coming again.Time limit:$ MS Memory Limit:262144KB 64bit IO for Mat:%i64d %i64u SubmitStatusPracticecodeforces 151BDescriptionWinters is just damn freezing cold in nvodsk! That's why a group of n friends prefers-a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend have a phonebook of size si (that's the number of phone numbers). We know
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.