﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-Design&amp;Art-随笔分类-设计模式</title><link>http://www.cppblog.com/abware/category/3898.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 27 May 2008 21:01:32 GMT</lastBuildDate><pubDate>Tue, 27 May 2008 21:01:32 GMT</pubDate><ttl>60</ttl><item><title>OO设计原则</title><link>http://www.cppblog.com/abware/archive/2008/05/28/51350.html</link><dc:creator>安帛伟</dc:creator><author>安帛伟</author><pubDate>Tue, 27 May 2008 19:11:00 GMT</pubDate><guid>http://www.cppblog.com/abware/archive/2008/05/28/51350.html</guid><wfw:comment>http://www.cppblog.com/abware/comments/51350.html</wfw:comment><comments>http://www.cppblog.com/abware/archive/2008/05/28/51350.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/abware/comments/commentRss/51350.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/abware/services/trackbacks/51350.html</trackback:ping><description><![CDATA[开闭原则（OCP）：对扩展开放，对修改封闭<br>里氏代换原则（LSP）：子类可替换父类，反之不行<br>依赖倒置原则（DIP）：依赖于抽象而不是依赖与具体<br>接口隔离原则（ISP）：多个专门接口比一个总接口好<br>合成/聚合复用原则（CARP）：尽量使用合成/聚合，而不是继承<br>迪米特法则（LoD）：不要和陌生人说话<br>
<img src ="http://www.cppblog.com/abware/aggbug/51350.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/abware/" target="_blank">安帛伟</a> 2008-05-28 03:11 <a href="http://www.cppblog.com/abware/archive/2008/05/28/51350.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Command模式</title><link>http://www.cppblog.com/abware/archive/2007/05/21/24573.html</link><dc:creator>安帛伟</dc:creator><author>安帛伟</author><pubDate>Mon, 21 May 2007 15:32:00 GMT</pubDate><guid>http://www.cppblog.com/abware/archive/2007/05/21/24573.html</guid><wfw:comment>http://www.cppblog.com/abware/comments/24573.html</wfw:comment><comments>http://www.cppblog.com/abware/archive/2007/05/21/24573.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/abware/comments/commentRss/24573.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/abware/services/trackbacks/24573.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Command模式的目的是为了使命令请求方与命令的执行方解耦合。<br>因解耦合可得到的好处是：1. 增加新的具体命令不影响其他的类；2. 可以把多个命令聚合在一起组成命令队列。<br>Command模式的缺点：使用命令模式会导致某些系统有过多的具体命令类。<br>&nbsp;&nbsp;<a href='http://www.cppblog.com/abware/archive/2007/05/21/24573.html'>阅读全文</a><img src ="http://www.cppblog.com/abware/aggbug/24573.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/abware/" target="_blank">安帛伟</a> 2007-05-21 23:32 <a href="http://www.cppblog.com/abware/archive/2007/05/21/24573.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>工厂方法和抽象工厂</title><link>http://www.cppblog.com/abware/archive/2007/03/25/20577.html</link><dc:creator>安帛伟</dc:creator><author>安帛伟</author><pubDate>Sun, 25 Mar 2007 15:20:00 GMT</pubDate><guid>http://www.cppblog.com/abware/archive/2007/03/25/20577.html</guid><wfw:comment>http://www.cppblog.com/abware/comments/20577.html</wfw:comment><comments>http://www.cppblog.com/abware/archive/2007/03/25/20577.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/abware/comments/commentRss/20577.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/abware/services/trackbacks/20577.html</trackback:ping><description><![CDATA[
		<p>工厂方法和抽象工厂实际上是从不同角度在描述问题。<br />工厂方法描述了具体产品的创建，而抽象工厂描述的是产品系列的组织。</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000"> Computer.cpp : Defines the entry point for the console application.<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #008000">//<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">stdafx.h</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #0000ff">string</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_165_166_Open_Image" onclick="this.style.display='none'; Codehighlighter1_165_166_Open_Text.style.display='none'; Codehighlighter1_165_166_Closed_Image.style.display='inline'; Codehighlighter1_165_166_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_165_166_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_165_166_Closed_Text.style.display='none'; Codehighlighter1_165_166_Open_Image.style.display='inline'; Codehighlighter1_165_166_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> Ram</span>
				<span id="Codehighlighter1_165_166_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_165_166_Open_Text">
						<span style="COLOR: #000000">{}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_193_194_Open_Image" onclick="this.style.display='none'; Codehighlighter1_193_194_Open_Text.style.display='none'; Codehighlighter1_193_194_Closed_Image.style.display='inline'; Codehighlighter1_193_194_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_193_194_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_193_194_Closed_Text.style.display='none'; Codehighlighter1_193_194_Open_Image.style.display='inline'; Codehighlighter1_193_194_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> IBMRam: </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> Ram</span>
				<span id="Codehighlighter1_193_194_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_193_194_Open_Text">
						<span style="COLOR: #000000">{}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_220_221_Open_Image" onclick="this.style.display='none'; Codehighlighter1_220_221_Open_Text.style.display='none'; Codehighlighter1_220_221_Closed_Image.style.display='inline'; Codehighlighter1_220_221_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_220_221_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_220_221_Closed_Text.style.display='none'; Codehighlighter1_220_221_Open_Image.style.display='inline'; Codehighlighter1_220_221_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> HPRam: </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> Ram</span>
				<span id="Codehighlighter1_220_221_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_220_221_Open_Text">
						<span style="COLOR: #000000">{}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_233_234_Open_Image" onclick="this.style.display='none'; Codehighlighter1_233_234_Open_Text.style.display='none'; Codehighlighter1_233_234_Closed_Image.style.display='inline'; Codehighlighter1_233_234_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_233_234_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_233_234_Closed_Text.style.display='none'; Codehighlighter1_233_234_Open_Image.style.display='inline'; Codehighlighter1_233_234_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> Cpu</span>
				<span id="Codehighlighter1_233_234_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_233_234_Open_Text">
						<span style="COLOR: #000000">{}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_261_262_Open_Image" onclick="this.style.display='none'; Codehighlighter1_261_262_Open_Text.style.display='none'; Codehighlighter1_261_262_Closed_Image.style.display='inline'; Codehighlighter1_261_262_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_261_262_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_261_262_Closed_Text.style.display='none'; Codehighlighter1_261_262_Open_Image.style.display='inline'; Codehighlighter1_261_262_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> IBMCpu: </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> Cpu</span>
				<span id="Codehighlighter1_261_262_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_261_262_Open_Text">
						<span style="COLOR: #000000">{}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img id="Codehighlighter1_288_289_Open_Image" onclick="this.style.display='none'; Codehighlighter1_288_289_Open_Text.style.display='none'; Codehighlighter1_288_289_Closed_Image.style.display='inline'; Codehighlighter1_288_289_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_288_289_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_288_289_Closed_Text.style.display='none'; Codehighlighter1_288_289_Open_Image.style.display='inline'; Codehighlighter1_288_289_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> HPCpu: </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> Cpu</span>
				<span id="Codehighlighter1_288_289_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_288_289_Open_Text">
						<span style="COLOR: #000000">{}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> Computer<br /><img id="Codehighlighter1_308_661_Open_Image" onclick="this.style.display='none'; Codehighlighter1_308_661_Open_Text.style.display='none'; Codehighlighter1_308_661_Closed_Image.style.display='inline'; Codehighlighter1_308_661_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_308_661_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_308_661_Closed_Text.style.display='none'; Codehighlighter1_308_661_Open_Image.style.display='inline'; Codehighlighter1_308_661_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_308_661_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_308_661_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> Computer(</span>
						<span style="COLOR: #0000ff">string</span>
						<span style="COLOR: #000000"> strName, Ram</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> pRam, Cpu</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> pCpu)<br /><img id="Codehighlighter1_367_485_Open_Image" onclick="this.style.display='none'; Codehighlighter1_367_485_Open_Text.style.display='none'; Codehighlighter1_367_485_Closed_Image.style.display='inline'; Codehighlighter1_367_485_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_367_485_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_367_485_Closed_Text.style.display='none'; Codehighlighter1_367_485_Open_Image.style.display='inline'; Codehighlighter1_367_485_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span>
						<span id="Codehighlighter1_367_485_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_367_485_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  m_strName </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> strName;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  m_pRam </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> pRam;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  m_pCpu </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> pCpu;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  cout</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">A </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000"> m_strName </span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> computer is produced</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #000000">~</span>
						<span style="COLOR: #000000">Computer()<br /><img id="Codehighlighter1_501_595_Open_Image" onclick="this.style.display='none'; Codehighlighter1_501_595_Open_Text.style.display='none'; Codehighlighter1_501_595_Closed_Image.style.display='inline'; Codehighlighter1_501_595_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_501_595_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_501_595_Closed_Text.style.display='none'; Codehighlighter1_501_595_Open_Image.style.display='inline'; Codehighlighter1_501_595_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span>
						<span id="Codehighlighter1_501_595_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_501_595_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  delete m_pRam;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  delete m_pCpu;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  cout</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">A </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000"> m_strName </span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000"> computer is deleted</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">string</span>
						<span style="COLOR: #000000"> m_strName;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> Ram</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> m_pRam;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> Cpu</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> m_pCpu;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> ComputerProducer<br /><img id="Codehighlighter1_688_885_Open_Image" onclick="this.style.display='none'; Codehighlighter1_688_885_Open_Text.style.display='none'; Codehighlighter1_688_885_Closed_Image.style.display='inline'; Codehighlighter1_688_885_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_688_885_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_688_885_Closed_Text.style.display='none'; Codehighlighter1_688_885_Open_Image.style.display='inline'; Codehighlighter1_688_885_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_688_885_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_688_885_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> Computer</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> createComputer()<br /><img id="Codehighlighter1_727_790_Open_Image" onclick="this.style.display='none'; Codehighlighter1_727_790_Open_Text.style.display='none'; Codehighlighter1_727_790_Closed_Image.style.display='inline'; Codehighlighter1_727_790_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_727_790_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_727_790_Closed_Text.style.display='none'; Codehighlighter1_727_790_Open_Image.style.display='inline'; Codehighlighter1_727_790_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span>
						<span id="Codehighlighter1_727_790_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_727_790_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> Computer(setName(), createRam(), createCpu());<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">virtual</span>
						<span style="COLOR: #000000"> Ram</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> createRam() </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">virtual</span>
						<span style="COLOR: #000000"> Cpu</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> createCpu() </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">virtual</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">string</span>
						<span style="COLOR: #000000"> setName() </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> IBMProducer: </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> ComputerProducer<br /><img id="Codehighlighter1_932_1182_Open_Image" onclick="this.style.display='none'; Codehighlighter1_932_1182_Open_Text.style.display='none'; Codehighlighter1_932_1182_Closed_Image.style.display='inline'; Codehighlighter1_932_1182_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_932_1182_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_932_1182_Closed_Text.style.display='none'; Codehighlighter1_932_1182_Open_Image.style.display='inline'; Codehighlighter1_932_1182_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_932_1182_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_932_1182_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">virtual</span>
						<span style="COLOR: #000000"> Ram</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> createRam()<br /><img id="Codehighlighter1_969_1032_Open_Image" onclick="this.style.display='none'; Codehighlighter1_969_1032_Open_Text.style.display='none'; Codehighlighter1_969_1032_Closed_Image.style.display='inline'; Codehighlighter1_969_1032_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_969_1032_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_969_1032_Closed_Text.style.display='none'; Codehighlighter1_969_1032_Open_Image.style.display='inline'; Codehighlighter1_969_1032_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span>
						<span id="Codehighlighter1_969_1032_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_969_1032_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  cout</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">A IBMRam is producted</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> IBMRam;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">virtual</span>
						<span style="COLOR: #000000"> Cpu</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> createCpu()<br /><img id="Codehighlighter1_1061_1124_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1061_1124_Open_Text.style.display='none'; Codehighlighter1_1061_1124_Closed_Image.style.display='inline'; Codehighlighter1_1061_1124_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1061_1124_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1061_1124_Closed_Text.style.display='none'; Codehighlighter1_1061_1124_Open_Image.style.display='inline'; Codehighlighter1_1061_1124_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span>
						<span id="Codehighlighter1_1061_1124_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1061_1124_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  cout</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">A IBMCPU is producted</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> IBMCpu;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">virtual</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">string</span>
						<span style="COLOR: #000000"> setName()<br /><img id="Codehighlighter1_1153_1180_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1153_1180_Open_Text.style.display='none'; Codehighlighter1_1153_1180_Closed_Image.style.display='inline'; Codehighlighter1_1153_1180_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1153_1180_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1153_1180_Closed_Text.style.display='none'; Codehighlighter1_1153_1180_Open_Image.style.display='inline'; Codehighlighter1_1153_1180_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span>
						<span id="Codehighlighter1_1153_1180_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1153_1180_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">string</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">IBM</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> HPProducer: </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> ComputerProducer<br /><img id="Codehighlighter1_1228_1473_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1228_1473_Open_Text.style.display='none'; Codehighlighter1_1228_1473_Closed_Image.style.display='inline'; Codehighlighter1_1228_1473_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1228_1473_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1228_1473_Closed_Text.style.display='none'; Codehighlighter1_1228_1473_Open_Image.style.display='inline'; Codehighlighter1_1228_1473_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1228_1473_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1228_1473_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000">:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">virtual</span>
						<span style="COLOR: #000000"> Ram</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> createRam()<br /><img id="Codehighlighter1_1265_1326_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1265_1326_Open_Text.style.display='none'; Codehighlighter1_1265_1326_Closed_Image.style.display='inline'; Codehighlighter1_1265_1326_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1265_1326_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1265_1326_Closed_Text.style.display='none'; Codehighlighter1_1265_1326_Open_Image.style.display='inline'; Codehighlighter1_1265_1326_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span>
						<span id="Codehighlighter1_1265_1326_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1265_1326_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  cout</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">A HPRam is producted</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> HPRam;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">virtual</span>
						<span style="COLOR: #000000"> Cpu</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> createCpu()<br /><img id="Codehighlighter1_1355_1416_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1355_1416_Open_Text.style.display='none'; Codehighlighter1_1355_1416_Closed_Image.style.display='inline'; Codehighlighter1_1355_1416_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1355_1416_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1355_1416_Closed_Text.style.display='none'; Codehighlighter1_1355_1416_Open_Image.style.display='inline'; Codehighlighter1_1355_1416_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span>
						<span id="Codehighlighter1_1355_1416_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1355_1416_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  cout</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">A HPCPU is producted</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">&lt;&lt;</span>
								<span style="COLOR: #000000">endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> HPCpu;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">virtual</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">string</span>
						<span style="COLOR: #000000"> setName()<br /><img id="Codehighlighter1_1445_1471_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1445_1471_Open_Text.style.display='none'; Codehighlighter1_1445_1471_Closed_Image.style.display='inline'; Codehighlighter1_1445_1471_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_1445_1471_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1445_1471_Closed_Text.style.display='none'; Codehighlighter1_1445_1471_Open_Image.style.display='inline'; Codehighlighter1_1445_1471_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" /> </span>
						<span id="Codehighlighter1_1445_1471_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_1445_1471_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">string</span>
								<span style="COLOR: #000000">(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">HP</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /> }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main(</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> argc, </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> argv[])<br /><img id="Codehighlighter1_1510_1809_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1510_1809_Open_Text.style.display='none'; Codehighlighter1_1510_1809_Closed_Image.style.display='inline'; Codehighlighter1_1510_1809_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_1510_1809_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_1510_1809_Closed_Text.style.display='none'; Codehighlighter1_1510_1809_Open_Image.style.display='inline'; Codehighlighter1_1510_1809_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_1510_1809_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_1510_1809_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> client code</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000"> ComputerProducer</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> pIBMFac</span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> IBMProducer;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> ComputerProducer</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> pHPFac </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">new</span>
						<span style="COLOR: #000000"> HPProducer;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> Computer</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> pIBMComputer </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> pIBMFac</span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">createComputer();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> Computer</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> pHPComputer </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> pHPFac </span>
						<span style="COLOR: #000000">-&gt;</span>
						<span style="COLOR: #000000">createComputer();<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> delete pIBMComputer;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> delete pHPComputer;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> delete pIBMFac;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> delete pHPFac;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
		<p>这个例子比较清楚了，不同的工厂生产不同的计算机，但计算机的基本组成(这里假设计算机仅由ram和cpu组成)是一样的，这样的产品系列很适合用抽象工厂来组织。<br />而在实际生产计算机的时候，createRam()和createCpu()这两个工厂方法又起到了作用。<br /></p>
<img src ="http://www.cppblog.com/abware/aggbug/20577.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/abware/" target="_blank">安帛伟</a> 2007-03-25 23:20 <a href="http://www.cppblog.com/abware/archive/2007/03/25/20577.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>