﻿<?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++博客-相信有一天，会变成高手！</title><link>http://www.cppblog.com/caishuzhi/</link><description>编程</description><language>zh-cn</language><lastBuildDate>Tue, 09 Jun 2026 17:42:20 GMT</lastBuildDate><pubDate>Tue, 09 Jun 2026 17:42:20 GMT</pubDate><ttl>60</ttl><item><title>C++编程模型</title><link>http://www.cppblog.com/caishuzhi/archive/2012/09/09/190030.html</link><dc:creator>才淑志</dc:creator><author>才淑志</author><pubDate>Sun, 09 Sep 2012 06:19:00 GMT</pubDate><guid>http://www.cppblog.com/caishuzhi/archive/2012/09/09/190030.html</guid><wfw:comment>http://www.cppblog.com/caishuzhi/comments/190030.html</wfw:comment><comments>http://www.cppblog.com/caishuzhi/archive/2012/09/09/190030.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/caishuzhi/comments/commentRss/190030.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/caishuzhi/services/trackbacks/190030.html</trackback:ping><description><![CDATA[本文属于抄录。
<hr />
<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">一种语言代表了一种思维，而思维决定了问题的解决方式。</span> <span lang="ZH-CN"></span><o:p></o:p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><o:p></o:p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">从程序设计语言出现到现在已经经历了四代。大多数高级语言都对应到第三代或四代程序设计语言。按其主要支持的编程模型（思维模式）分类，大致可以分为如下类型</span> <span lang="ZH-CN"></span><o:p></o:p></p>
<p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; tab-stops: list 36.0pt" class="MsoNormal"><span style="mso-fareast-font-family: 'Times New Roman'">1</span> <span style="font-family: 宋体; mso-bidi-font-family: 宋体" lang="ZH-CN">．</span> <span style="mso-fareast-font-family: 'Times New Roman'" lang="ZH-CN"></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">过程型：这类语言把应用抽象为序列化的操作步骤，其典型代表如</span>PASCAL<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">，</span>C<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">等。</span><o:p></o:p></p>
<p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; tab-stops: list 36.0pt" class="MsoNormal"><span style="mso-fareast-font-family: 'Times New Roman'">2</span> <span style="font-family: 宋体; mso-bidi-font-family: 宋体" lang="ZH-CN">．</span> <span style="mso-fareast-font-family: 'Times New Roman'" lang="ZH-CN"></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">函数型：这类语言把应用抽象为函数（按定义，函数是从一个域到另一个域的映射）；它们试图把问题分解为集合和集合间的函数关系。典型代表是</span>LISP<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">。</span><o:p></o:p></p>
<p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; tab-stops: list 36.0pt" class="MsoNormal"><span style="mso-fareast-font-family: 'Times New Roman'">3</span> <span style="font-family: 宋体; mso-bidi-font-family: 宋体" lang="ZH-CN">．</span> <span style="mso-fareast-font-family: 'Times New Roman'" lang="ZH-CN"></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">逻辑型：这类语言把问题抽象为事实与规则的结合，试图通过逻辑演算解决实际问题。典型代表是</span>PROLOG<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">。</span><o:p></o:p></p>
<p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; tab-stops: list 36.0pt" class="MsoNormal"><span style="mso-fareast-font-family: 'Times New Roman'">4</span> <span style="font-family: 宋体; mso-bidi-font-family: 宋体" lang="ZH-CN">．</span> <span style="mso-fareast-font-family: 'Times New Roman'" lang="ZH-CN"></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">面向对象型：这类语言从上世纪</span>80<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">年代后迅速发展，这类语言试图将实际问题抽象为独立的对象以及对象间的交互，典型代表是早期的</span>SmallTalk<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">和</span>Eiffel<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">。</span><o:p></o:p></p>
<p style="text-indent: -18pt; margin: 0cm 0cm 0pt 36pt; tab-stops: list 36.0pt" class="MsoNormal"><span style="mso-fareast-font-family: 'Times New Roman'">5</span> <span style="font-family: 宋体; mso-bidi-font-family: 宋体" lang="ZH-CN">．</span> <span style="mso-fareast-font-family: 'Times New Roman'" lang="ZH-CN"></span><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">面向数据结构型：这类语言将问题抽象为对结构化数据的操作，例如现在常用的</span>SQL<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">。</span><o:p></o:p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><o:p></o:p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">作为一个诞生与上世纪</span>80<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">年代初期的编程语言，</span>C++<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">被广泛的认为是一种支持面向对象的语言；但是，我认为</span>C++<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">的伟大之处却更多的在于（除了所提供完备的面向对象支持）它同样提供了</span>C<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">的面向过程的编程模型以及只有少数高级语言能支持的范型编程（我更喜欢叫它面向算法的编程）。在实际的应用过程中，我们往往需要不同层次的抽象，</span>C++<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">所支持的广泛的编程模型为我们提供了强大和灵活的工具，使得我们在设计和实现时能自如的选择不同的模型，以最合理的（组合）方式解决问题。</span><o:p></o:p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><o:p></o:p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">不可否认，在当今的程序设计中，面向对象已经基本上是一统江湖，但它往往并不是最合理的选择；例如在针对协议栈的开发中，使用面向过程的模型往往优于使用面向对象的模型（或许这也是为什么主流的电信设备供应商坚持使用</span>C<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">的原因？）；而在针对算法进行抽象时，使用面向对象的思维模式几乎完全是不可行的（算法和对象间的不同之处是显而易见的）；如果机械的运用面向对象思维，只能使最终产品的质量、可维护性、可读性下降。</span><o:p></o:p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><o:p></o:p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">或许有人会问，那么应该如何选择抽象方式呢？我觉得这个应该是因人和问题的不同而不同的，关键是在使用</span>C++<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">的过程中，多从这些方面进行思考、总结，以体会采用不同模式解决问题的优缺点，努力使用最合理的方式（或组合）对问题进行抽象并加以解决。我也常常为这些种种选择而迷惑，因此在这儿也希望那些已经到了&#8220;不惑&#8221;层次的哥们多多指教。</span><o:p></o:p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><o:p></o:p></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">当然，从另一方面来说，越多的选择往往意味着越难的选择，这或许也是为什么现在这么多人趋骛与更单纯、更简单的</span>JAVA<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">，</span>C#<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">的原因吧；但是当我们真正理解并掌握</span>C++<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">提供的这些编程模型时，我想我们会更加坚定当初选择</span>C++<span style="font-family: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'" lang="ZH-CN">的信念。</span></p>  <img src ="http://www.cppblog.com/caishuzhi/aggbug/190030.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/caishuzhi/" target="_blank">才淑志</a> 2012-09-09 14:19 <a href="http://www.cppblog.com/caishuzhi/archive/2012/09/09/190030.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>