面向?qū)ο蠛虲++畢業(yè)論文外文翻譯_第1頁
面向?qū)ο蠛虲++畢業(yè)論文外文翻譯_第2頁
面向?qū)ο蠛虲++畢業(yè)論文外文翻譯_第3頁
面向?qū)ο蠛虲++畢業(yè)論文外文翻譯_第4頁
已閱讀5頁,還剩14頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、面向?qū)ο蠛虲+C+ 是目前所使用的眾多編程語言中的一種。為什么會(huì)有那么多的語言?為什么總會(huì)有新的語言不斷出現(xiàn)?編程語言可以幫助程序員方便實(shí)現(xiàn)從設(shè)計(jì)到實(shí)現(xiàn)。第一個(gè)編程語言對(duì)基本的機(jī)器結(jié)構(gòu)有很大的依賴性。這時(shí)程序的細(xì)節(jié)很笨重。只有硬件設(shè)計(jì)師了解如何在其他成分之外建立計(jì)算機(jī)體系,語言設(shè)計(jì)者同樣認(rèn)識(shí)到程序可以在一個(gè)高水平的環(huán)境編寫,因而是程序員可以不必了解機(jī)器的細(xì)節(jié)。為什么有這么多高水平的編程語言?有很多語言可以訪問大型數(shù)據(jù)庫,格式化金融報(bào)告,控制機(jī)器人在工廠工作,處理機(jī)件,控制衛(wèi)星實(shí)時(shí)模擬核反應(yīng)堆,預(yù)測變化的大氣層狀況,下棋和繪制電路圖。每一個(gè)問題都需要不同的數(shù)據(jù)結(jié)構(gòu)和算法。程序語言作為一種工具幫助

2、我們解決這些問題。然而,并不是一種程序語言可以最好的解決所有問題。新的語言被開發(fā)來更好的解決一類特定的問題。其他語言可以用來解決不同的問題領(lǐng)域和多方面的用途。每個(gè)程序語言固定一個(gè)特定的程序體系或設(shè)計(jì)程序原理。使用多種多樣的語言建立不同的設(shè)計(jì)方案。這些方案被叫做程序范例,幫助我們思考問題,規(guī)范解決。通過范例設(shè)計(jì)軟件當(dāng)設(shè)計(jì)一個(gè)小的計(jì)算機(jī)程序或大的軟件系統(tǒng)是,我們要思考問題的解決模式。怎樣去設(shè)計(jì)一個(gè)模式?程序范例提供了許多不同的方法去設(shè)計(jì)和思考軟件系統(tǒng)。一個(gè)范例可以被認(rèn)為是一個(gè)模式或者一個(gè)框架來設(shè)計(jì)和描述軟件結(jié)構(gòu)。這個(gè)模式幫助我們?nèi)ニ伎己鸵?guī)范解決。我們可以選擇一種語言,使用范例獨(dú)立的完成。當(dāng)所選擇的

3、語言提供的結(jié)構(gòu)和機(jī)制符合范例時(shí),就很容易完成。一般來說,幾種語言可能屬于同一種范例。因此,一種范例可以被看作一種語言的類。一種語言不僅要符合一種范例,而且能夠使用多種范例提供的特性和特征?;旌险Z言,如 C+ ,綜合了兩到三種范例。 C+ 包括了命令和程序范例的特性,例如,其前身 C,和面向?qū)ο蠓独C罘独好罘独奶匦允怯?jì)算機(jī)的抽象模型和巨大的內(nèi)存存儲(chǔ)。這是計(jì)算機(jī)體系的 von Neumann 模型。計(jì)算命令,由一系列的命令組成,以代碼形式存儲(chǔ)。命令可以使機(jī)器找到解決方法,使用指定命令改變存儲(chǔ),變量讀取,算術(shù)和邏輯表達(dá)式,條件分枝控制執(zhí)行流。程序范例:它包括了命令范例,還有對(duì)概念命令和表達(dá)

4、的抽象機(jī)制。參數(shù),即存儲(chǔ)的一部分,被引進(jìn)在范例中。還包括重復(fù),選擇等特征。許多主流程序還是這種語言。程序范例在程序設(shè)計(jì)中首次引進(jìn)了抽象的概念。抽象可以把動(dòng)作和結(jié)果隔離。過程是抽象的表格,完成一些任務(wù)或功能。其他部分調(diào)用時(shí),只是正確有效的執(zhí)行,但不清楚過程的執(zhí)行。程序范例和 ADT :數(shù)據(jù)抽象使一個(gè)數(shù)據(jù)對(duì)象的行為和它的描述或執(zhí)行相分離。用戶無法看到數(shù)據(jù)的基本操作,執(zhí)行可以方便的更改而不影響程序的運(yùn)行。當(dāng)我們?cè)O(shè)計(jì)一個(gè)算法時(shí),需要一個(gè)特定的數(shù)據(jù)類型執(zhí)行算法的操作。如果可以定義變量的數(shù)據(jù)類型,而不影響到實(shí)際數(shù)據(jù)類型的運(yùn)行,就可以很容易的制訂出算法。通過定義數(shù)據(jù)的用法和操作,假定可以選擇任何一種運(yùn)行,這

5、種定義就叫做抽象數(shù)據(jù)類型。抽象數(shù)據(jù)類型的使用使得算法的設(shè)計(jì)得到更大的推廣,使得我們?cè)谒惴ㄔO(shè)計(jì)時(shí),注重了算法的全面,而不會(huì)拘泥于運(yùn)行的細(xì)節(jié)。當(dāng)算法設(shè)計(jì)完成時(shí),實(shí)際的數(shù)據(jù)類型被執(zhí)行。近來,程序語言擴(kuò)展到支持新的數(shù)據(jù)類型的定義和提供便利給數(shù)據(jù)抽象。面向?qū)ο蟮姆独核匀槐A袅嗽S多程序范例的特征,過程仍然是計(jì)算的主要形式。但是,程序不僅僅是抽象值的運(yùn)算,在面向?qū)ο蠓独N還有對(duì)對(duì)象的運(yùn)算。對(duì)象同抽象數(shù)據(jù)類型很相似,聯(lián)系著數(shù)據(jù)和運(yùn)算。面向?qū)ο蠓独哂腥N主要特性,第一種,壓縮,其機(jī)制是為了實(shí)施數(shù)據(jù)抽象。第二種,繼承。繼承允許從已存在的對(duì)象中創(chuàng)建新的對(duì)象。這個(gè)新創(chuàng)建的對(duì)象是原對(duì)象的具體說明。新對(duì)象的不同在于

6、只需要提供方法或數(shù)據(jù)。當(dāng)一個(gè)對(duì)象從另一個(gè)對(duì)象中被創(chuàng)建或取得時(shí),就說新對(duì)象繼承了它父對(duì)象的方法和數(shù)據(jù),并增加了一些新的描述和說明。面向?qū)ο蟮牡谌N特性是多態(tài)。多態(tài)可以使不同類型的的對(duì)象對(duì)相同的信息執(zhí)行相同的操作。例如,我們有一部分對(duì)象它們可以執(zhí)行一類操作,但是只有在運(yùn)行時(shí)我們才知道對(duì)象的類型。面向?qū)ο笳Z言包含的機(jī)制確保了每一類信息傳遞給正確的對(duì)象。壓縮,繼承和多態(tài)被認(rèn)為是面向?qū)ο蟪绦虻幕咎卣?,所有的面向?qū)ο蟪绦蛘Z言必須提供這些特征。一般來說,語言通過不同的途徑支持這些特征的實(shí)現(xiàn)。Smalltalk, C+, Objective-C,和 Lisp with CLOS (the Common Li

7、sp ObjectSystem) 這些程序語言都是面向?qū)ο笳Z言的例子,它們都可以提供對(duì)壓縮,繼承和多態(tài)的支持。構(gòu)建一個(gè)面向?qū)ο蟮某绦蛐枰獩Q定解決問題所需的對(duì)象。這些對(duì)象被用來構(gòu)建計(jì)算,定義軟件系統(tǒng)的操作運(yùn)行。信息的傳遞是對(duì)象間最基本的相互作用機(jī)制。信息(從其他的對(duì)象或程序)傳遞給對(duì)象,以便通知對(duì)象運(yùn)行下一個(gè)操作。對(duì)象需要負(fù)責(zé)維護(hù)它所相關(guān)的數(shù)據(jù)的狀態(tài)。只有對(duì)象本身才可以改變它內(nèi)部的數(shù)據(jù)值。對(duì)象本身可以完全的調(diào)用它的子對(duì)象。一個(gè)對(duì)象的執(zhí)行是一個(gè)循環(huán)遞歸的過程,當(dāng)定義這個(gè)對(duì)象和方法的初始值是,可以跳出這個(gè)循環(huán)遞歸的過程。這時(shí),這個(gè)方法和數(shù)據(jù)所組成的元素可以使用程序語言所提供的基本的構(gòu)造函數(shù)。學(xué)習(xí)面向

8、對(duì)象范例最重要的一點(diǎn)是如何改變我們思考建造軟件體系的思路。系統(tǒng)被認(rèn)為是由多個(gè)單一獨(dú)立的個(gè)體組成,其中每個(gè)個(gè)體只負(fù)責(zé)對(duì)其自身的操作的運(yùn)行。每一個(gè)對(duì)象的設(shè)置和運(yùn)行都是自身所包含的。由于對(duì)象常常模仿真實(shí)世界的個(gè)體的概念,因而這樣的一個(gè)模型推動(dòng)了軟件方面的設(shè)計(jì)(以及后來的實(shí)行)。設(shè)計(jì)一個(gè)系統(tǒng)使用面向?qū)ο蟮姆独瑥亩沟孟到y(tǒng)的操作和運(yùn)行更類似于真實(shí)世界中所對(duì)應(yīng)的真實(shí)個(gè)體。C+ 面向?qū)ο蟮奶匦詨嚎s: C+ 繼承了 C 的發(fā)展,并且定義的新的方便的數(shù)據(jù)類型。一個(gè)類就像C的結(jié)構(gòu),但不同的是同時(shí)包括了數(shù)據(jù)和方法。除此之外, C+ 還提供了類中各個(gè)成員訪問權(quán)限的不同,以此方便的控制即使是在不同的類,也可以訪問類中

9、的成員。重復(fù)的調(diào)用一個(gè)抽象的數(shù)據(jù)可以對(duì)用戶隱藏對(duì)一個(gè)數(shù)據(jù)對(duì)象的操作細(xì)節(jié)。用戶只可以通過一個(gè)公共的接口來訪問這個(gè)對(duì)象。一個(gè)C+ 的類既包括共有的部分,又包括私有的部分。公有的部分提供給用戶關(guān)于這個(gè)類的接口,私有的部分只有構(gòu)造這個(gè)類的函數(shù)才可以訪問。C+ 提供了關(guān)鍵字來說明類中哪些成員是不可見的,哪些部分是其公共接口。不可見的成員在其定義的部分標(biāo)明了關(guān)鍵字private 。公共的接口部分標(biāo)有關(guān)鍵字public 。當(dāng)一個(gè)類是私有的類時(shí),意味著只有這個(gè)類的函數(shù)或友元可以使用它。一個(gè)類的定義并不分配內(nèi)存。當(dāng)一個(gè)數(shù)據(jù)對(duì)象被創(chuàng)建并且具有變量聲明時(shí)才分配內(nèi)存。構(gòu)造函數(shù)和析構(gòu)函數(shù)提供了對(duì)象的初始化和釋放功能。當(dāng)

10、一個(gè)對(duì)象被聲明時(shí),它的構(gòu)造函數(shù)初始化其在內(nèi)存的值。當(dāng)對(duì)象離開它所在的范圍時(shí),調(diào)用析構(gòu)函數(shù)釋放對(duì)象。我們不可能對(duì)用戶完全的隱藏操作的細(xì)節(jié)。 C+ 無法提供一個(gè)使所有細(xì)節(jié)完全排除在基本操作之外的方法,因此一個(gè)類的私有部分必須這個(gè)類的定義,從而有效的訪問這個(gè)類的變量,并可以繼承。建造一個(gè)類可以使它方便的訪問它父類的私有成員。 C+ 定義了關(guān)鍵字 protected 來完成繼承的實(shí)現(xiàn)。 保護(hù)成員既可以被類的成員函數(shù)訪問,也可以被派生類的成員函數(shù)訪問。和私有成員相同的一點(diǎn),保護(hù)成員不可以被用戶程序訪問。對(duì)象所需要注意的最后一點(diǎn),信息的重復(fù)傳遞時(shí)對(duì)象間交流的基本功能。例如一個(gè)語句 i < a2.Si

11、ze() ,我們可以有效的把信息傳給a2 的對(duì)象,以確定組的大小并返回其值。實(shí)際上,這里并沒有真的傳遞信息。C+ 通過調(diào)用函數(shù)模擬信息的傳遞。編譯器確保對(duì)所需要的對(duì)象調(diào)用正確的函數(shù),因此,在 C+ 中,可以把信息的傳遞當(dāng)作函數(shù)的調(diào)用。當(dāng)設(shè)計(jì)了一種方案,一種程序語言就可以被選擇執(zhí)行。可以在設(shè)計(jì)的過程中找到對(duì)象間的繼承關(guān)系,甚至可以使用傳統(tǒng)的,非面向?qū)ο蟮恼Z言設(shè)計(jì)系統(tǒng)。但是,使用面向?qū)ο笳Z言,如 C+ ,由于語言支持對(duì)象間的繼承關(guān)系,從而可以更方便的了解設(shè)計(jì)執(zhí)行。C+ 語言是混合型的語言,它屬于多范例的語言。C+ 可以認(rèn)為是 C 語言的擴(kuò)展的過程語言或面向?qū)ο笳Z言。C+ 面向?qū)ο筇卣鰿+ 繼承:任

12、何面向?qū)ο蟪绦蛘Z言其最主要的作用就是可以從原有的類中創(chuàng)建新的類,從而可以再次使用代碼。繼承可以從與原有的類型擴(kuò)展到派生類型。面向?qū)ο笤O(shè)計(jì)的一個(gè)主要操作就是要確認(rèn)真實(shí)世界的個(gè)體以及各個(gè)個(gè)體之間的聯(lián)系。當(dāng)設(shè)計(jì)一個(gè)軟件系統(tǒng)時(shí),需要建立一系列的對(duì)象,并且需要互相關(guān)聯(lián)的一系列對(duì)象。有些類之間可能不是完全的相關(guān)。大部分的類之間可以歸納為繼承的關(guān)系。將一系列的類歸為一個(gè)類的層次需要明白各個(gè)類之間的關(guān)系和他們之間的細(xì)節(jié)。但不是所有的類之間都可以建立繼承的關(guān)系。C+ 提供了三種方式的繼承:公有繼承,私有繼承,保護(hù)繼承。這些不同的方式應(yīng)用在不同的對(duì)象間關(guān)系。第一種關(guān)系是 IS-A 關(guān)系。這種關(guān)系是類型與類型, 類

13、與類之間特有的關(guān)系。 IS-A 繼承指兩個(gè)類,其中一個(gè)類描述了對(duì)對(duì)象的說明,對(duì)對(duì)象的設(shè)置說明由另一個(gè)類來說明。 IS-A 的關(guān)系是傳統(tǒng)的繼承關(guān)系,也就是派生類型。派生類型是一些基本類型即父類型的專門化,在 C+ 中,超級(jí)類型就是基類,派生類型就是派生類。在 C+ 中執(zhí)行 IS-A 關(guān)系需要使用公有繼承。 在基類中的公共部分使用公有繼承,在派生類中也是公有的部分,在基類中的保護(hù)部分使用公有繼承,在派生類中也變成保護(hù)的部分有時(shí)在兩個(gè)對(duì)象之間的關(guān)系也許是包含關(guān)系,也可以是部分整體之間的關(guān)系。不是所有對(duì)象它都是其他對(duì)象的一個(gè)專門說明和繼承,可能這些對(duì)象有些是其他對(duì)象的一部分或是包含在其他的對(duì)象中。在

14、C+ 中使用 HAS-A 關(guān)系可以使用成員或是私有繼承。 例如,一個(gè)堆??梢员划?dāng)作一個(gè)數(shù)組使用。我們可以使用堆棧作為一個(gè)數(shù)據(jù)成員 ,或者使用私有繼承,從數(shù)組類中繼承堆棧類??梢栽趦蓚€(gè)類之間使用繼承創(chuàng)建一個(gè)互相包含的關(guān)系。私有繼承只有在不是接口的部分可以被使用,基類是一個(gè)細(xì)節(jié)的執(zhí)行。在私有繼承的情況下,原來基類中的公有部分和保護(hù)部分,在派生類中都變?yōu)樗接胁糠?。派生類的使用者不可以訪問基類中的接口。但是派生類中的成員函數(shù)可以自由的訪問或調(diào)用基類中的公共部分和私有部分。當(dāng)這樣使用基類中的成員時(shí),用戶不可以只依靠繼承來編寫代碼。這是一個(gè)修改為不同的基類的運(yùn)行。繼承的另一種方式,也是很少使用的一種方式就

15、是保護(hù)繼承。保護(hù)繼承也是一種可以使用 HAS-A 關(guān)系的繼承。當(dāng)使用保護(hù)繼承時(shí),在基類中的公有部分和保護(hù)部分,在派生類中就都變?yōu)楸Wo(hù)部分。當(dāng)繼承是接口的部分時(shí),派生類要使用保護(hù)繼承,但是不是接口的所有部分都可以被用戶使用。一個(gè)保護(hù)的基類類似于一個(gè)私有的基類,不同在于繼承的派生類可以知道接口部分。如果可以的話,最好使用數(shù)據(jù)成員。這時(shí)當(dāng)你必須重復(fù)使用基類中的函數(shù)時(shí),可以使用其繼承。如果你所有的派生類是基類的一個(gè)說明構(gòu)造時(shí),只有使用公有繼承,否則,要使用私有繼承。當(dāng)在不必要時(shí)使用繼承,會(huì)使系統(tǒng)更加難以理解??傊?,一個(gè)類有兩個(gè)主要的接口:一個(gè)是給用戶所使用的(公共接口),另一個(gè)派生類所使用(公有部分和

16、保護(hù)部分的聯(lián)合)。繼承的部分是基本相同的。在基類中的公共接口使用公有繼承,在派生類中隊(duì)用戶也是公有接口。在基類中的公共部分和保護(hù)部分使用保護(hù)繼承,在派生類中可以使用成員函數(shù),但并不對(duì)派生類的所有用戶。最后,當(dāng)在基類中的公共部分和保護(hù)部分使用私有繼承,基類可以調(diào)用,但用戶和派生類不可以使用。C+ 多態(tài):多態(tài)是面向?qū)ο蟪绦虻娜齻€(gè)特性中最重要的部分。多態(tài),和繼承一起,對(duì)面向?qū)ο蟪绦蛴泻艽蟮挠猛尽6鄳B(tài),就是說有多個(gè)形式,提供一個(gè)基本的軟件接口以建立不同類型的對(duì)象操作的統(tǒng)一的方式。 C+ 提供了三種類型的多態(tài):虛函數(shù),函數(shù)重載和運(yùn)算符重載。虛函數(shù)可以使繼承的同層相關(guān)的對(duì)象用同一種方式操作。當(dāng)所有的函數(shù)傳

17、遞同樣的信息值時(shí),虛函數(shù)的機(jī)制確保在動(dòng)態(tài)運(yùn)行時(shí)了調(diào)用正確的函數(shù)。一個(gè)類的普通的成員函數(shù)是靜態(tài)的單一的過程,在編譯時(shí)調(diào)用。它只有一個(gè)對(duì)成員函數(shù)的說明使用于類中所有的例子。當(dāng)定義一個(gè)成員函數(shù)時(shí),在它前面加上關(guān)鍵字 virtual ,實(shí)際過程的調(diào)用依賴于對(duì)象實(shí)例的類型,通過這樣來判斷如何調(diào)用。這是一個(gè)動(dòng)態(tài)的約束。靜態(tài)方式的束定也叫做早期束定。虛函數(shù)機(jī)制可以通過一個(gè)基類的參數(shù)或指針調(diào)用。一個(gè)基類的指針可以指向一個(gè)基本類型的對(duì)象或任何從基類派生出的類型的對(duì)象。虛函數(shù)也可以用在邏輯的運(yùn)算上。一個(gè)類是抽象的類當(dāng)這個(gè)類是繼承的根節(jié)點(diǎn)時(shí)。一個(gè)類當(dāng)它只有虛函數(shù)的定義而沒有實(shí)現(xiàn)時(shí)是抽象類。這些函數(shù)在類定義時(shí)被賦予

18、0 值。派生類必須給出他們的實(shí)現(xiàn)。另一個(gè)多態(tài)的形式是函數(shù)重載。當(dāng)一個(gè)函數(shù)被使用在多個(gè)程序時(shí)就是重載。重載允許在同樣的名稱下執(zhí)行一系列相似的功能。當(dāng)有相同函數(shù)時(shí),編譯器通過檢查它的返回值和參數(shù)決定哪個(gè)被調(diào)用。當(dāng)我們定義新的數(shù)據(jù)類型時(shí),需要定義相似類型的標(biāo)準(zhǔn)的操作。一個(gè)復(fù)數(shù)的類型要有加減的運(yùn)算。我們可以使用運(yùn)算符重載加減操作就像整形和浮點(diǎn)型數(shù)據(jù)。運(yùn)算符的定義和 C+ 函數(shù)的定義相似,可以作為類的成員或非成員。運(yùn)算符有一個(gè)或兩個(gè)參數(shù)分別叫做單目或雙目運(yùn)算符。在C+ 中,一個(gè)運(yùn)算符函數(shù)的定義就像一個(gè)成員函數(shù)的定義,在其名字的前面加上關(guān)鍵字operator 。 C+ 在運(yùn)算符的重載上有一些限制,只有先定

19、義運(yùn)算符的操作才可以被重載,只定義了運(yùn)算符就重載是錯(cuò)誤的。你不能把單目運(yùn)算符返回到雙目運(yùn)算或多目運(yùn)算中。同時(shí),范圍運(yùn)算(:'), 成員運(yùn)算 (.*'), 類運(yùn)算 (.'), 選擇運(yùn)算 (?:') 不能重載。在這后兩點(diǎn)的面向?qū)ο蠓治鲋校覀兛梢钥吹紺+ 很好的支持了面向?qū)ο蟮姆独?。Object-Orientation and C+C+ is just one of many programming languages in use today. Why are there so many languages? Why do new ones appear ever

20、y few years? Programming languages have evolved to help programmers ease the transition from design to implementation.The first programming languages were very dependent on the underlying machine architecture. Writing programs at this level of detail is very cumbersome. Just as hardware engineers le

21、arned how to build computer systems out of other components, language designers also realized that programs could be written at a much higher level, thereby shielding the programmer from the details of the underlying machine.Why are there such a large number of high-level programming languages? Ther

22、e are languages for accessing large inventory databases, formatting financial reports, controlling robots on the factory floor, processing lists, controlling satellites in real time, simulating a nuclear reactor, predicting changing atmospheric conditions, playing chess, and drawing circuit boards.

23、Each of these problems requires different sets of data structures and algorithms. Programming languages are tools to help us solve problems. However, there is not one programming language that is best for every type of problem. New programming languages are often developed to provide better tools fo

24、r solving a particular class of problems. Other languages are intended to be useful for a variety of problem domains and are more general purpose.Each programming language imparts a particular programming style or design philosophy on its programmers. With the multitude of programming languages avai

25、lable today, a number of such design philosophies have emerged. These design philosophies, called programming paradigms, help us to think about problems and formulate solutions.Software Design through ParadigmsWhen designingsmall computerprogramsor large softwaresystems, we oftenhave a mental model

26、of the problem we are trying to solve. How do we devise amental model of a software system? Programming paradigms offer many differentways of designing and thinking about software systems. A paradigm can be thought of as a mental model or as a framework for designing and describing asoftware system&

27、#39;s structure. The model helps us think about and formulate solutions.We can use the mental model of a paradigm independently from the programming language chosen for implementation. However, when the chosen language provides constructs and mechanisms that are similar to those that are found in th

28、e paradigm, the implementation will be more straightforward. Usually, there are several languages that belong to a paradigm. For this reason, a programming paradigm is also considered a class of languages.A language does not have to fit into just one paradigm. More often, languages provide features

29、or characteristics from several paradigms. Hybrid languages, such as C+, combine characteristics from two or more paradigms. C+ includes characteristics from the imperative and procedural paradigms - just like its predecessor language, C - and the object-oriented paradigm.THE IMPERATIVE PARADIGM.The

30、 imperative paradigm is characterized byan abstract model of a computer with a large memory store. This is the classic von Neumann model of computer architecture. Computations, which consist of a sequence of commands, are stored as encoding within the store. Commands enable the machine to find solut

31、ions using assignment to modify the store, variables to read the store, arithmetic and logic to evaluate expressions, and conditional branching to control the flow of execution.THE PROCEDURAL PARADIGM.The procedural paradigm includes theimperative paradigm, but extends it with an abstraction mechani

32、sm for generalizing commands and expressions into procedures. Parameters, which are essentially aliases for a portion of the store, were also introduced by this paradigm. Other features include iteration, recursion, and selection. Most mainstreams programming today is done in a procedural language.T

33、he procedural paradigm was the first paradigm to introduce the notion of abstraction into program design. The purpose of abstraction in programming is to separate behavior from implementation. Procedures are a form of abstraction. The procedure performs some task or function. Other parts of the prog

34、ram call the procedure, knowing that it will perform the task correctly and efficiently, but without knowing exactly how the procedure is implemented.THE PROCEDURAL PARADIGM WITH ADTs.DATA ABSTRACTIONisconcerned with separating the behavior of a data object from its representation or implementation.

35、 For example, a stack contains the operations Push, Pop, and IsEmpty. A stack object provides users with these operations, but does not reveal how the stack is actually implemented. The stack could be implemented using an array or a list. Users of the stack object do not care how the stack is implem

36、ented, only that it performs the above operations correctly and efficiently. Because the underlying implementation of the data object is hidden from its users, the implementation can easily be changed without affecting the programs that use it.When we design algorithms, we often need a particular da

37、ta type to use in order to carry out the algorithm's operations. The design of an algorithm is easier if we simply specify the data types of the variables, without worrying about how the actual data type is implemented. We describe the data type by its properties and operations and assume that w

38、hatever implementation is chosen, the operations will work correctly and efficiently. Types defined in this way are called ABSTRACT DATA TYPES (ADTs).The use of abstract data types makes the design of the algorithm more general, and allows us to concentrate on the algorithm at hand without getting b

39、ogged down in implementation details. After the algorithms have been designed, the actual data types will need to be implemented, along with the algorithms. Recently,procedural languages have been extended to support the definition of new data types and provide facilities for data abstraction.THE OB

40、JECT-ORIENTED PARADIGM.The object- oriented paradigmretains much of the characteristics of the procedural paradigm, since procedures are still the primary form for composing computations. However, rather than operate on abstract values, programs in the object-oriented paradigm operate on objects. An

41、 object is very similar to an abstract data type and contains data as well as procedures.There are three primary characteristics of the object-oriented paradigm. We have already described the first, ENCAPSULATION , the mechanism for enforcing data abstraction. The second characteristic is INHERITANC

42、E . Inheritance allows new objects to be created from existing, more general ones. The new object becomes a specialized version of the general object. New objects need only provide the methods or data that differ because of the specialization. When an object is created (or derived) from another obje

43、ct, it is said to inherit the methods and data of the parent object, and includes any new representations and new or revised methods added to it.The third and final characteristic of object-oriented programming is POLYMORPHISM . Polymorphism allows many different types of objects to perform the same

44、 operation by responding to the same message. For example, we may have a collection of objects which can all perform a sort operation. However, we do not know what types of objects will be created until run-time. Object-oriented languages contain mechanisms for ensuring that each sort message is sen

45、t to the right object.Encapsulation, inheritance, and polymorphism are considered the fundamental characteristics of object-oriented programming and all object-oriented languagesmust provide these characteristics in some way. Not surprisingly, languages support these characteristics in very differen

46、t ways. Smalltalk, C+, Objective-C, and Lisp with CLOS (the Common Lisp Object System) are all examples of object-oriented languages, and each provides support for encapsulation, inheritance, and polymorphism.Constructing an object-oriented program involves determining the objects that are needed to

47、 solve the problem. The objects are then used to construct computations that define the behavior of the software system. Message passing is the fundamental interaction mechanism among objects. Messages (from other objects or programs) are sent to objects to inform them to perform one of their operat

48、ions.Objects are responsible for maintaining the state of their data. Only the object may modify its internal data. Objects may themselves be implemented via other sub-objects. Implementing an object involves a recursive process of breaking it into sub-objects until at some level the objects and met

49、hods defined on them are primitives. At this point, the methods and data consist of elements that can be implemented using the basic constructs provided by the programming language.One of the most important aspects of the object-oriented paradigm is how it changes our way of thinking about software

50、systems. Systems are thought of as consisting of individual entities that are responsible for carrying out their own operations. Each object is conceived and implemented as self-contained. Such a model facilitates software design (and later implementation) because objects often model conceptual real

51、-world entities. Designing systems using the object-oriented paradigm results in software systems that behave and appear more like their real-life counterparts.The Object-Oriented Characteristics of C+ENCAPSULATION in C+.C+ extends C with a facility for defining new datatypes. A class is like a C st

52、ruct, but contains data as well as methods. In addition, C+ provides different levels of access to the members of a class in order to control how the members of a class can be manipulated from outside the class.Recall that the importance of data abstraction is to hide the implementationdetails of a

53、data object from the user. The user only accesses the object through its PUBLIC INTERFACE. A C+ class consists of a public and private part. The public part provides the interface to the users of the class, while the private part can only be used by the functions that make up the class.C+ provides k

54、eywords to indicate which members of a class are hidden and which are part of its public interface. The members of the hidden implementation are marked in sections beginning with the keyword private. The public interface part of the class follows the keyword public. By default, the declarations with

55、in a class are private, meaning that only the member functions (and friends) of the class have access to them.A class definition does not allocate any memory. Memory is allocated when an array object is created through a variable declaration. Constructors and destructors provide the initialization a

56、nd clean up of an object. When an object is declared, the constructor is called to initialize the memory used by the object. The destructor performs any clean-up for the object when the object goes out of scope and is destroyed.Note that we didn't really hide the implementation details from the

57、user. C+ does not provide a way to completely exclude all of the details of the underlying implementation, since the private part of the class must be included with the class definition it is useful to relax the access to variables within a class, particularly under inheritance. Often derived classes need ea

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論