Wxwidgets Student Information Management sqlite3 under Ubuntu

Source: Internet
Author: User
Tags wxwidgets

Simple Factory is the creation mode of a class, also known as the Static Factory method (Factory) mode.

A simple factory model is a factory class that determines which product class to create based on the parameters passed in.

There are 4 characters

Factory class role: A direct caller of the specific product class role.

Abstract product role: an interface or abstract class that is responsible for defining specific product roles and interacting with clients.

Specific product roles: objects created by the factory class, and also the client's actual action object.

Client: Call the factory class to produce the instance and invoke the method of the instance to work accordingly.


C + + implementation

#include <iostream>

#include <list>


using namespace Std;
Class Pizza
{
Public
String name;
string dough;
string sauce;
List<string> pizzalist;
void Prepare ()
{
cout<< "Preparing" +name<<endl;
cout<< "tossing dough ..." <<endl;
cout<< "Adding sauce ..." <<endl;
cout<< "Adding pizzalist:" <<endl;
For (List<string>::iterator It=pizzalist.begin (); It!=pizzalist.end (); it++)
{
cout<< "" <<*it<<endl;
}
}
virtual void bake ()
{
cout<< "Bake for minutes at" <<endl;
}
virtual void cut ()
{
cout<< "cutting the pizza into diagonal slices" <<endl;
}
virtual void box ()
{
cout<< "Place Pizza in official Pizzastore box" <<endl;
}
String GetName ()
{
return name;
}
};
Class Nystylecheesepizza:public Pizza
{
Public
Nystylecheesepizza ()
{
Name= "NY Style Sauce and Cheese Pizza";
dough= "Thin crust dough";
sauce= "marinara sauce";
Pizzalist.push_back ("grated Reggiano Cheese");
}
};
Class Chicagostylecheesepizza:public Pizza
{
Public
Chicagostylecheesepizza ()
{
Name= "Chicago Style deep Dish Cheese Pizza";
Dough= "Extra Thick crust Dough";
sauce= "Plum Tomato sauce";
Pizzalist.push_back ("shredded mozzarella Cheese");
}
void Cut ()
{
cout<< "cutting the pizza into square slices";
}


};
Class Pizzastore
{
Public:
Pizza Orderpizza (String type)
{
Pizza Pizza;
Pizza=creatpizza (type);
Pizza.prepare ();
Pizza.bake ();
Pizza.cut ();
Pizza.box ();
return pizza;
}
Protected
Virtual Pizza Creatpizza (String type) = 0;
};
Class Nystylepizzastore:public Pizzastore
{
Pizza Creatpizza (String item)
{
if (item== "cheese")
{
Nystylecheesepizza NY;
return NY;
}
}


};
Class Chicagostylestore:public Pizzastore
{
Pizza Creatpizza (String item)
{
if (item== "cheese")
{
Chicagostylecheesepizza Chicago;
return Chicago;
}


}
};
int main ()
{
Pizzastore *nystore=new Nystylepizzastore ();
Pizzastore *chicagostore=new Chicagostylestore ();
Pizza Pizza =nystore->orderpizza ("cheese");
cout<< "Ethan ordered a" +pizza.getname () <<endl;
Pizza =chicagostore->orderpizza ("cheese");
cout<< "Joel ordered a" +pizza.getname () <<endl;
return 0;
}

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.