<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>冒号论坛 &#187; Topic: 抽象机制</title>
		<link>http://bbs.zhenghui.org/topic/%e6%8a%bd%e8%b1%a1%e6%9c%ba%e5%88%b6</link>
		<description>冒号论坛 &raquo; Topic: 抽象机制</description>
		<language>en-US</language>
		<pubDate>Wed, 08 Sep 2010 13:02:37 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://bbs.zhenghui.org/search.php</link>
		</textInput>
		<atom:link href="http://bbs.zhenghui.org/rss/topic/%e6%8a%bd%e8%b1%a1%e6%9c%ba%e5%88%b6" rel="self" type="application/rss+xml" />

		<item>
			<title>hui on "抽象机制"</title>
			<link>http://bbs.zhenghui.org/topic/%e6%8a%bd%e8%b1%a1%e6%9c%ba%e5%88%b6#post-50</link>
			<pubDate>Mon, 15 Feb 2010 18:27:26 +0000</pubDate>
			<dc:creator>hui</dc:creator>
			<guid isPermaLink="false">50@http://bbs.zhenghui.org/</guid>
			<description>&#60;p&#62;Java在开始引入foreach时遭到一些非议，认为是无多大用处的语法糖。不过只要能让代码更简洁、可读性更高、更不容易出bug，便是语法糖又何妨？何况这样的用法的确提高了抽象的层次，让同样的表达适用于更多的underlying容器（甚至包括最基本的数组），对底层变化的适应力更强。
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Todd on "抽象机制"</title>
			<link>http://bbs.zhenghui.org/topic/%e6%8a%bd%e8%b1%a1%e6%9c%ba%e5%88%b6#post-49</link>
			<pubDate>Mon, 15 Feb 2010 12:13:53 +0000</pubDate>
			<dc:creator>Todd</dc:creator>
			<guid isPermaLink="false">49@http://bbs.zhenghui.org/</guid>
			<description>&#60;p&#62;更明白了，谢谢！&#60;/p&#62;
&#60;p&#62;关于迭代抽象，我最早习惯C的for(int i; i &#38;lt; n; i++)，但有时不小心就会出现死循环，而foreach不存在死循环问题，所以逐渐开始用后者了。这也印证了抽象层次越高越普适越可靠。
&#60;/p&#62;</description>
		</item>
		<item>
			<title>hui on "抽象机制"</title>
			<link>http://bbs.zhenghui.org/topic/%e6%8a%bd%e8%b1%a1%e6%9c%ba%e5%88%b6#post-48</link>
			<pubDate>Sat, 13 Feb 2010 16:05:51 +0000</pubDate>
			<dc:creator>hui</dc:creator>
			<guid isPermaLink="false">48@http://bbs.zhenghui.org/</guid>
			<description>&#60;p&#62;&#60;em&#62;过程抽象&#60;/em&#62;赋予程序员自定义函数或运算的能力。参数抽象和规范抽象在其中的体现应该是明显的，以开方函数sqrt(double number)为例:&#60;br /&#62;
number可以是任何一个非负double型变量，这是参数抽象；调用者不必关心sqrt的实现，只根据它的规范便确信sqrt(a)将保证返回a的一个平方根，这是规范抽象。&#60;/p&#62;
&#60;p&#62;&#60;em&#62;数据抽象&#60;/em&#62;赋予程序员自定义数据类型的能力。参数抽象和规范抽象在其中的体现与过程抽象是类似的。&#60;em&#62;类型层级&#60;/em&#62;和&#60;em&#62;多态抽象&#60;/em&#62;则是在数据抽象的基础上融入了类族和多态的因素。&#60;/p&#62;
&#60;p&#62;&#60;em&#62;迭代抽象&#60;/em&#62;赋予程序员自定义循环的能力。在没有迭代抽象时，程序员如果需要遍历一个容器，需要关注不少的细节：如何获取容器的元素？何处是起点？何处是终点？遍历的方式（顺序、倒序、随机、跳跃）？这不仅增加了客户的负担，也限制了容器今后的变化（担心影响到客户）。&#60;br /&#62;
以Java的Iterator为例：&#60;br /&#62;
public interface Iterator&#38;lt;E&#38;gt;{&#60;br /&#62;
    boolean hasNext(); // Returns true if the iteration has more elements.&#60;br /&#62;
    E next();          // Returns the next element in the iteration.&#60;br /&#62;
    void remove();     // Removes from the underlying collection the last element&#60;br /&#62;
}&#60;br /&#62;
要遍历一个容器，只需要获取它的一个Iterator对象即可。在这里，Iterator便是一个&#60;strong&#62;规范抽象&#60;/strong&#62;，其规范体现在hasNext、next和remove的文档描述上。&#60;br /&#62;
更简单地，只要容器实现了Iterable接口，便可采用for-each循环：&#60;br /&#62;
for (ElementType element : elements) process(element);&#60;br /&#62;
在这里，连hasNext和next的调用都被隐去了，可以认为抽象得到了进一步的提升，此时迭代已经上升到了语言层面（借鉴了C#语法）。
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Todd on "抽象机制"</title>
			<link>http://bbs.zhenghui.org/topic/%e6%8a%bd%e8%b1%a1%e6%9c%ba%e5%88%b6#post-47</link>
			<pubDate>Fri, 12 Feb 2010 19:31:13 +0000</pubDate>
			<dc:creator>Todd</dc:creator>
			<guid isPermaLink="false">47@http://bbs.zhenghui.org/</guid>
			<description>&#60;p&#62;第7课P186讲到：借助这两种抽象机制（参数抽象和规范抽象），我们可以实现五类基本抽象：过程抽象、数据抽象、迭代抽象、类型层级、多态抽象。&#60;/p&#62;
&#60;p&#62;还不是很明白这两种抽象机制与五类基本抽象的关系。比如：迭代抽象如何体现了参数抽象和规范抽象。
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
