<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Google Stop Blog - The future is fusion &#187; Design Pattern</title>
	<atom:link href="http://googlestop.com/blog/category/design-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://googlestop.com/blog</link>
	<description>Just another weblog of Charry</description>
	<lastBuildDate>Sat, 10 Jul 2010 13:02:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>建立自己的消息循环(续)</title>
		<link>http://googlestop.com/blog/2007/05/%e5%bb%ba%e7%ab%8b%e8%87%aa%e5%b7%b1%e7%9a%84%e6%b6%88%e6%81%af%e5%be%aa%e7%8e%af%e7%bb%ad/</link>
		<comments>http://googlestop.com/blog/2007/05/%e5%bb%ba%e7%ab%8b%e8%87%aa%e5%b7%b1%e7%9a%84%e6%b6%88%e6%81%af%e5%be%aa%e7%8e%af%e7%bb%ad/#comments</comments>
		<pubDate>Tue, 22 May 2007 13:21:55 +0000</pubDate>
		<dc:creator>Charry</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Design Pattern]]></category>

		<guid isPermaLink="false">http://googlestop.com/blog/2007/05/22/%e5%bb%ba%e7%ab%8b%e8%87%aa%e5%b7%b1%e7%9a%84%e6%b6%88%e6%81%af%e5%be%aa%e7%8e%af%e7%bb%ad/</guid>
		<description><![CDATA[前面的帖子《建立自己的消息循环》中提到使用从CCmdTarget派生的类作为消息传递的载体，但这种方法不能传递多余的参数(也许可以，但我不知道怎么搞:)。为了使这个机制支持大多数的消息，我把前面的例子改动了一下，把那些用于消息处理的类，改为从CWnd派生，然后再Create这些窗口。这样这些类其实就是个标准的窗口了，只是我没有把它们显示出来。 本例和前面的例子，主要用在那些多使用消息机制的Project中，其实也可以不必这么做，完全可以直接去调用类的方法。但是如果消息机制比较适合，此方法不失为一种选择。 点击这里下载Demo]]></description>
			<content:encoded><![CDATA[<p>前面的帖子《<a href="http://googlestop.com/blog/2007/05/18/%e5%bb%ba%e7%ab%8b%e8%87%aa%e5%b7%b1%e7%9a%84%e6%b6%88%e6%81%af%e5%be%aa%e7%8e%af/">建立自己的消息循环</a>》中提到使用从CCmdTarget派生的类作为消息传递的载体，但这种方法不能传递多余的参数(也许可以，但我不知道怎么搞:)。为了使这个机制支持大多数的消息，我把前面的例子改动了一下，把那些用于消息处理的类，改为从CWnd派生，然后再Create这些窗口。这样这些类其实就是个标准的窗口了，只是我没有把它们显示出来。</p>
<p>本例和前面的例子，主要用在那些多使用消息机制的Project中，其实也可以不必这么做，完全可以直接去调用类的方法。但是如果消息机制比较适合，此方法不失为一种选择。</p>
<p>点击<a href="http://www.googlestop.com/download/MsgDemo.zip">这里</a>下载Demo</p>
]]></content:encoded>
			<wfw:commentRss>http://googlestop.com/blog/2007/05/%e5%bb%ba%e7%ab%8b%e8%87%aa%e5%b7%b1%e7%9a%84%e6%b6%88%e6%81%af%e5%be%aa%e7%8e%af%e7%bb%ad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>建立自己的消息循环</title>
		<link>http://googlestop.com/blog/2007/05/%e5%bb%ba%e7%ab%8b%e8%87%aa%e5%b7%b1%e7%9a%84%e6%b6%88%e6%81%af%e5%be%aa%e7%8e%af/</link>
		<comments>http://googlestop.com/blog/2007/05/%e5%bb%ba%e7%ab%8b%e8%87%aa%e5%b7%b1%e7%9a%84%e6%b6%88%e6%81%af%e5%be%aa%e7%8e%af/#comments</comments>
		<pubDate>Fri, 18 May 2007 14:48:50 +0000</pubDate>
		<dc:creator>Charry</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Design Pattern]]></category>

		<guid isPermaLink="false">http://googlestop.com/blog/2007/05/18/%e5%bb%ba%e7%ab%8b%e8%87%aa%e5%b7%b1%e7%9a%84%e6%b6%88%e6%81%af%e5%be%aa%e7%8e%af/</guid>
		<description><![CDATA[在MFC程序中使用消息机制的时候，常常会在程序即将完成的时候发现，在某个窗口中加入了太多的消息处理宏，并且这些消息的Handler和UI界面的方法混合在一起，待到项目规模大的时候，会导致后续的维护越来越困难。我们希望将UI的动作和业务处理的动作隔离开，互不影响，我们可以模仿MFC的消息流转机制，就本文来说，是Command的流转(Command Routing)，大家知道，所有的从CCmdTarget派生的类都可以支持消息处理，比如CDocument, CView, CDocTemplate等。Framework在内部使用了Chain of Responsiblity。消息会在一个链条上找到自己的执行的地方，我们可以把不同的业务逻辑分割为各个不同的环，我们可以在修改一个环的情况下，而不去影响其他的环。附件中的例子只是简单的发送一个WM_COMMAND消息，消息的ID，表示了不同的动作。此方法适合发送消息时候，参数很少或者不用参数的情况。  示例代码的简单说明： 业务处理类需要从CCmdTarget派生 在每个业务处理类里面加入适当的消息映射(注意更新MyCommand.h中的消息的宏) 在CCmdManager类的BuildCmdTarget()中加入类的初始化 在主窗口的OnCmdMsg中调用 CCmdManager的CallOnCmdMsg方法 P.S. 这里写的只是MFC消息机制最粗糙的改造，由于时间的关系，这里不做过多的介绍 示例代码，点击这里下载]]></description>
			<content:encoded><![CDATA[<p>在MFC程序中使用消息机制的时候，常常会在程序即将完成的时候发现，在某个窗口中加入了太多的消息处理宏，并且这些消息的Handler和UI界面的方法混合在一起，待到项目规模大的时候，会导致后续的维护越来越困难。我们希望将UI的动作和业务处理的动作隔离开，互不影响，我们可以模仿MFC的消息流转机制，就本文来说，是Command的流转(Command Routing)，大家知道，所有的从CCmdTarget派生的类都可以支持消息处理，比如CDocument, CView, CDocTemplate等。Framework在内部使用了Chain of Responsiblity。消息会在一个链条上找到自己的执行的地方，我们可以把不同的业务逻辑分割为各个不同的环，我们可以在修改一个环的情况下，而不去影响其他的环。附件中的例子只是简单的发送一个WM_COMMAND消息，消息的ID，表示了不同的动作。此方法适合发送消息时候，参数很少或者不用参数的情况。</p>
<p> 示例代码的简单说明：</p>
<ol>
<li>业务处理类需要从CCmdTarget派生</li>
<li>在每个业务处理类里面加入适当的消息映射(注意更新MyCommand.h中的消息的宏)</li>
<li>在CCmdManager类的BuildCmdTarget()中加入类的初始化</li>
<li>在主窗口的OnCmdMsg中调用 CCmdManager的CallOnCmdMsg方法</li>
</ol>
<p>P.S.<br />
这里写的只是MFC消息机制最粗糙的改造，由于时间的关系，这里不做过多的介绍</p>
<p>示例代码，点击<a href="http://www.googlestop.com/download/CommandTest.zip">这里</a>下载</p>
]]></content:encoded>
			<wfw:commentRss>http://googlestop.com/blog/2007/05/%e5%bb%ba%e7%ab%8b%e8%87%aa%e5%b7%b1%e7%9a%84%e6%b6%88%e6%81%af%e5%be%aa%e7%8e%af/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Here are some links about design pattern on the web</title>
		<link>http://googlestop.com/blog/2007/05/here-are-some-links-about-design-pattern-on-the-web/</link>
		<comments>http://googlestop.com/blog/2007/05/here-are-some-links-about-design-pattern-on-the-web/#comments</comments>
		<pubDate>Sat, 12 May 2007 18:12:03 +0000</pubDate>
		<dc:creator>Charry</dc:creator>
				<category><![CDATA[Design Pattern]]></category>

		<guid isPermaLink="false">http://googlestop.com/blog/2007/05/12/here-are-some-links-about-design-pattern-on-the-web/</guid>
		<description><![CDATA[http://www.dofactory.com/Patterns/Patterns.aspx http://home.earthlink.net/~huston2/dp/patterns.html If you&#8217;re new to Design Pattern, the links listed above may be helpful. the first one is easy to understand. it shows you the skeleton of every pattern and illustatues the details in real-world code. by the way, &#60;&#60;Head First Design Patter&#62;&#62; is also an amazing book for us, it&#8217;s the best seller [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dofactory.com/Patterns/Patterns.aspx">http://www.dofactory.com/Patterns/Patterns.aspx</a></p>
<p><a href="http://home.earthlink.net/~huston2/dp/patterns.html">http://home.earthlink.net/~huston2/dp/patterns.html</a></p>
<p>If you&#8217;re new to Design Pattern, the links listed above may be helpful. the first one is easy to understand. it shows you the skeleton of every pattern and illustatues the details in real-world code. by the way, &lt;&lt;Head First Design Patter&gt;&gt; is also an amazing book for us, it&#8217;s the best seller in many online bookshops recently.</p>
]]></content:encoded>
			<wfw:commentRss>http://googlestop.com/blog/2007/05/here-are-some-links-about-design-pattern-on-the-web/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Observer设计模式之软件语言的动态切换</title>
		<link>http://googlestop.com/blog/2007/03/observer%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e4%b9%8b%e8%bd%af%e4%bb%b6%e8%af%ad%e8%a8%80%e7%9a%84%e5%8a%a8%e6%80%81%e5%88%87%e6%8d%a2/</link>
		<comments>http://googlestop.com/blog/2007/03/observer%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e4%b9%8b%e8%bd%af%e4%bb%b6%e8%af%ad%e8%a8%80%e7%9a%84%e5%8a%a8%e6%80%81%e5%88%87%e6%8d%a2/#comments</comments>
		<pubDate>Sat, 24 Mar 2007 07:06:13 +0000</pubDate>
		<dc:creator>Charry</dc:creator>
				<category><![CDATA[Design Pattern]]></category>

		<guid isPermaLink="false">http://googlestop.com/2007/03/24/observer%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e4%b9%8b%e8%bd%af%e4%bb%b6%e8%af%ad%e8%a8%80%e7%9a%84%e5%8a%a8%e6%80%81%e5%88%87%e6%8d%a2/</guid>
		<description><![CDATA[随着网络的普及，软件的国际化问题，越来越值得让软件作者们多花些时间去思考。下面结合Observer模式，给出一个简单的多语言切换的例子。 语言切换其实有多种方法，不过常用的不外乎用文本（包括XML格式）、DLL等资源来保存语言，各有千秋。 下面的例子使用的是DLL，即所有的Dialog资源、字符串等都保存在DLL中，每种语言一个DLL。每个字符串所对应的ID是一样的，比如菜单中的 &#8220;File&#8221; 在English.DLL中，它的ID为 : IDS_MENU_FILE，对应的，它在Chinese.DLL中的ID也是IDS_MENU_FILE。这样，切换语言的时候，首先切换程序的DLL，然后再去读取这些ID对应的字符串，重新显示在界面中，就可以了。 切换语言后，所有界面都需要更新，显然这是个一对多的问题，Observer模式正好适用。所有需要支持多国语言的模块，都从下面的接口中派生： class IUIObserver { public: IUIObserver(void); virtual void UpdateUI() = 0; public: virtual ~IUIObserver(void); }; IUIObserver是个虚函数，它的继承者需要实现它，在UpdateUI方法中，各自完成自己的更新方法。比如某个Dialog： void CPreferencesDlg::UpdateUI() { CString title; title.LoadString(IDS_PPG_PREFERENCES); SetTitle(title); } 每个模块的UpdateUI方法各不相同，它们在必需要的时候被调用。下面是Subject的框架： class CUISubject { private: CUISubject(); virtual ~CUISubject(); static CUISubject * m_pInstance; std::list&#60;IUIObserver*&#62; m_listAllUI; public: static CUISubject * GetInstance(); static void FreeInstance(); public: void [...]]]></description>
			<content:encoded><![CDATA[<p>随着网络的普及，软件的国际化问题，越来越值得让软件作者们多花些时间去思考。下面结合Observer模式，给出一个简单的多语言切换的例子。</p>
<p><span id="more-20"></span>语言切换其实有多种方法，不过常用的不外乎用文本（包括XML格式）、DLL等资源来保存语言，各有千秋。 下面的例子使用的是DLL，即所有的Dialog资源、字符串等都保存在DLL中，每种语言一个DLL。每个字符串所对应的ID是一样的，比如菜单中的 &#8220;File&#8221; 在English.DLL中，它的ID为 : IDS_MENU_FILE，对应的，它在Chinese.DLL中的ID也是IDS_MENU_FILE。这样，切换语言的时候，首先切换程序的DLL，然后再去读取这些ID对应的字符串，重新显示在界面中，就可以了。</p>
<p>切换语言后，所有界面都需要更新，显然这是个一对多的问题，Observer模式正好适用。所有需要支持多国语言的模块，都从下面的接口中派生：</p>
<p>class IUIObserver<br />
{<br />
public:<br />
IUIObserver(void);</p>
<p>virtual void UpdateUI() = 0;</p>
<p>public:<br />
virtual ~IUIObserver(void);<br />
};</p>
<p>IUIObserver是个虚函数，它的继承者需要实现它，在UpdateUI方法中，各自完成自己的更新方法。比如某个Dialog：</p>
<p>void CPreferencesDlg::UpdateUI()<br />
{<br />
CString title;<br />
title.LoadString(IDS_PPG_PREFERENCES);<br />
SetTitle(title);<br />
}</p>
<p>每个模块的UpdateUI方法各不相同，它们在必需要的时候被调用。下面是Subject的框架：</p>
<p>class CUISubject<br />
{</p>
<p>private:<br />
CUISubject();<br />
virtual ~CUISubject();<br />
static CUISubject * m_pInstance;<br />
std::list&lt;IUIObserver*&gt; m_listAllUI;</p>
<p>public:<br />
static CUISubject * GetInstance();<br />
static void FreeInstance();</p>
<p>public:</p>
<p>void Attatch(IUIObserver* obs);<br />
void Detatch(IUIObserver* obs);<br />
void Notify();<br />
void SetState();<br />
int GetState();</p>
<p>};</p>
<p>Subject维护一个链表，其中保存了所有需要通知的UI界面，一旦语言切换了，Subject遍历这个链表，分别调用它们的UpdateUI方法，从而实现所有UI的语言切换。当某个Dialog初始化后，把自己Attach到链表中，如果它销毁了，千万不要忘记把自己从链表中Detach掉。上面的Subject同时也是个Singleton模式。</p>
<p>切换语言时候，工作如下:</p>
<p>void CUISubject::Notify()<br />
{<br />
std::list&lt;IUIObserver*&gt;::iterator it;</p>
<p>for (it=m_listAllUI.begin(); it!=m_listAllUI.end(); ++it)<br />
{<br />
IUIObserver *p = static_cast&lt;IUIObserver*&gt;(*it);<br />
if (p)<br />
{<br />
p-&gt;UpdateUI();<br />
}<br />
}<br />
}</p>
<p>附：AfxSetResourceHandle用来设置缺省资源。</p>
]]></content:encoded>
			<wfw:commentRss>http://googlestop.com/blog/2007/03/observer%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e4%b9%8b%e8%bd%af%e4%bb%b6%e8%af%ad%e8%a8%80%e7%9a%84%e5%8a%a8%e6%80%81%e5%88%87%e6%8d%a2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
