Skip to content

Commit 1d4ce4e

Browse files
author
jason_yao
committed
update
1 parent c92af86 commit 1d4ce4e

395 files changed

Lines changed: 13727 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Binary file not shown.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// AbstractFactory1.cpp: implementation of the AbstractFactory class.
2+
//
3+
//////////////////////////////////////////////////////////////////////
4+
5+
#include "stdafx.h"
6+
#include "AbstractFactory.h"
7+
8+
//////////////////////////////////////////////////////////////////////
9+
// Construction/Destruction
10+
//////////////////////////////////////////////////////////////////////
11+
12+
13+
#include "AbstractFactory.h"
14+
#include "Product.h"
15+
#include <iostream>
16+
using namespace std;
17+
18+
AbstractFactory::AbstractFactory(){}
19+
20+
AbstractFactory::~AbstractFactory(){}
21+
22+
ConcreteFactory1::ConcreteFactory1(){}
23+
24+
ConcreteFactory1::~ConcreteFactory1(){}
25+
26+
AbstractProductA* ConcreteFactory1::CreateProductA()
27+
{
28+
return new ProductA1();
29+
}
30+
31+
AbstractProductB* ConcreteFactory1::CreateProductB()
32+
{
33+
return new ProductB1();
34+
}
35+
//*
36+
ConcreteFactory2::ConcreteFactory2(){}
37+
38+
ConcreteFactory2::~ConcreteFactory2(){}
39+
40+
AbstractProductA* ConcreteFactory2::CreateProductA()
41+
{
42+
return new ProductA2();
43+
}
44+
45+
AbstractProductB* ConcreteFactory2::CreateProductB()
46+
{
47+
return new ProductB2();
48+
}
49+
//*/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// AbstractFactory1.h: interface for the AbstractFactory class.
2+
//
3+
//////////////////////////////////////////////////////////////////////
4+
5+
#if !defined(AFX_ABSTRACTFACTORY1_H__28CCA5AD_AF98_419D_9A80_4BBDE9CCD056__INCLUDED_)
6+
#define AFX_ABSTRACTFACTORY1_H__28CCA5AD_AF98_419D_9A80_4BBDE9CCD056__INCLUDED_
7+
8+
#if _MSC_VER > 1000
9+
#pragma once
10+
#endif // _MSC_VER > 1000
11+
12+
13+
class AbstractProductA;
14+
class AbstractProductB;
15+
16+
class AbstractFactory
17+
{
18+
public:
19+
virtual ~AbstractFactory();
20+
virtual AbstractProductA* CreateProductA()=0;
21+
virtual AbstractProductB* CreateProductB()=0;
22+
protected:
23+
AbstractFactory();
24+
private:
25+
};
26+
27+
28+
class ConcreteFactory1:public AbstractFactory
29+
{
30+
public:
31+
ConcreteFactory1();
32+
~ConcreteFactory1();
33+
AbstractProductA* CreateProductA();
34+
AbstractProductB* CreateProductB();
35+
protected:
36+
private:
37+
};
38+
39+
//*
40+
class ConcreteFactory2:public AbstractFactory
41+
{
42+
public:
43+
ConcreteFactory2();
44+
~ConcreteFactory2();
45+
AbstractProductA* CreateProductA();
46+
AbstractProductB* CreateProductB();
47+
protected:
48+
private:
49+
};
50+
//*/
51+
52+
#endif // !defined(AFX_ABSTRACTFACTORY1_H__28CCA5AD_AF98_419D_9A80_4BBDE9CCD056__INCLUDED_)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//AbstractFactory.cpp
2+
#include "stdafx.h"
3+
#include "AbstractFactory.h"
4+
#include "Product.h"
5+
#include <iostream>
6+
using namespace std;
7+
8+
int main(int argc, char* argv[])
9+
{
10+
AbstractProductA* proA;
11+
AbstractProductB* proB;
12+
13+
//生成工厂一对象
14+
AbstractFactory* cf1 = new ConcreteFactory1();
15+
//通过工厂一的方法 创建产品对象A
16+
proA=cf1->CreateProductA();
17+
//对象A的方法
18+
proA->fun();
19+
//(new ProductA1)->fun();
20+
21+
proB=cf1->CreateProductB();
22+
proB->fun();
23+
24+
AbstractFactory* cf2 = new ConcreteFactory2();
25+
proA=cf2->CreateProductA();
26+
proA->fun();
27+
proB=cf2->CreateProductB();
28+
proB->fun();
29+
printf("Hello World!\n");
30+
return 0;
31+
}

23種設計模式及對應C++示例代碼/创建型模式/AbstractFactory_exam/AbstractFactory_exam.dsp

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Microsoft Developer Studio Workspace File, Format Version 6.00
2+
# ����: ���ܱ༭��ɾ���ù������ļ���
3+
4+
###############################################################################
5+
6+
Project: "AbstractFactory_exam"=".\AbstractFactory_exam.dsp" - Package Owner=<4>
7+
8+
Package=<5>
9+
{{{
10+
}}}
11+
12+
Package=<4>
13+
{{{
14+
}}}
15+
16+
###############################################################################
17+
18+
Global:
19+
20+
Package=<5>
21+
{{{
22+
}}}
23+
24+
Package=<3>
25+
{{{
26+
}}}
27+
28+
###############################################################################
29+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<html>
2+
<body>
3+
<pre>
4+
<h1>Build Log</h1>
5+
<h3>
6+
--------------------Configuration: AbstractFactory_exam - Win32 Debug--------------------
7+
</h3>
8+
<h3>Command Lines</h3>
9+
Creating temporary file "C:\Users\hdy\AppData\Local\Temp\RSP2AE9.tmp" with contents
10+
[
11+
/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/AbstractFactory_exam.pch" /Yu"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
12+
"K:\ѧϰ\ģʽ���\������ģʽ\AbstractFactory_exam\AbstractFactory.cpp"
13+
"K:\ѧϰ\ģʽ���\������ģʽ\AbstractFactory_exam\AbstractFactory_exam.cpp"
14+
"K:\ѧϰ\ģʽ���\������ģʽ\AbstractFactory_exam\Product.cpp"
15+
]
16+
Creating command line "cl.exe @C:\Users\hdy\AppData\Local\Temp\RSP2AE9.tmp"
17+
Creating temporary file "C:\Users\hdy\AppData\Local\Temp\RSP2AEA.tmp" with contents
18+
[
19+
/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/AbstractFactory_exam.pch" /Yc"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
20+
"K:\ѧϰ\ģʽ���\������ģʽ\AbstractFactory_exam\StdAfx.cpp"
21+
]
22+
Creating command line "cl.exe @C:\Users\hdy\AppData\Local\Temp\RSP2AEA.tmp"
23+
Creating temporary file "C:\Users\hdy\AppData\Local\Temp\RSP2AEB.tmp" with contents
24+
[
25+
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/AbstractFactory_exam.pdb" /debug /machine:I386 /out:"Debug/AbstractFactory_exam.exe" /pdbtype:sept
26+
".\Debug\AbstractFactory.obj"
27+
".\Debug\AbstractFactory_exam.obj"
28+
".\Debug\Product.obj"
29+
".\Debug\StdAfx.obj"
30+
]
31+
Creating command line "link.exe @C:\Users\hdy\AppData\Local\Temp\RSP2AEB.tmp"
32+
<h3>Output Window</h3>
33+
Compiling...
34+
StdAfx.cpp
35+
Compiling...
36+
AbstractFactory.cpp
37+
AbstractFactory_exam.cpp
38+
Product.cpp
39+
Generating Code...
40+
Linking...
41+
42+
43+
44+
<h3>Results</h3>
45+
AbstractFactory_exam.exe - 0 error(s), 0 warning(s)
46+
</pre>
47+
</body>
48+
</html>

0 commit comments

Comments
 (0)