版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、<p> 南 京 理 工 大 學(xué) 紫 金 學(xué) 院</p><p> 畢業(yè)設(shè)計(論文)外文資料翻譯</p><p> 系: 計算機系 </p><p> 專 業(yè): 計算機科學(xué)與技術(shù) </p><p> 姓 名:
2、 張熙楚 </p><p> 學(xué) 號: 090601416 </p><p> 外文出處: Ghosh,D..Java Object-oriented programming[J]. IEEE Transactions on Softwa
3、re Engineering,2009, 13(3):42-45. </p><p> 附 件: 1.外文資料翻譯譯文;2.外文原文。 </p><p> 注:請將該封面與附件裝訂成冊。</p><p> 附件1:外文資料翻譯譯文</p><p> Java的面向?qū)ο缶幊?<
4、;/p><p> ——面向?qū)ο缶幊毯退年P(guān)鍵技術(shù)—繼承和多態(tài)性</p><p> 軟件的重用可以節(jié)省程序開發(fā)時間。它鼓勵重復(fù)使用已經(jīng)調(diào)試好的高質(zhì)量的軟件,從而減少系統(tǒng)運行后可能出現(xiàn)的問題。這些都是令人振奮的可能性。多態(tài)性允許我們用統(tǒng)一的風(fēng)格編寫程序,來處理多種已存在的類和特定的相關(guān)類。利用多態(tài)性我們可以方便地向系統(tǒng)中添加新的功能。繼承和多態(tài)對于解決軟件的復(fù)雜性是一種有效可行的技術(shù)。當(dāng)創(chuàng)建一
5、個新的類時,而不用完整的寫出新的實例變量和實例方法,程序員會指定新的類繼承已定義的超類的實例變量和實例方法。這個新的類被稱為一個子類。每個子類本身將來亦可有新的子類,而其本身將成為父類。一個類的直接父類就是該類所直接繼承的類(通過關(guān)鍵字extends繼承)。一個間接超類是通過從兩級或更多級以上的類繼承而來的。例如,從類JApplet(包javax.swing中)擴展來的類Applet(包java.applet)。一個類單一的從一個父類繼
6、承而來。 Java不支持多重繼承(而C++可以),但它支持接口的概念。接口可以使Java實現(xiàn)許多通過多重繼承才能實現(xiàn)的優(yōu)點而沒有關(guān)聯(lián)的問題。我們將在本章討論的接口的詳細內(nèi)容。我們會給出創(chuàng)建和使用接口的一般規(guī)律和具體實例。一個子類通常添加自己的實例變量</p><p> 開發(fā)軟件的實踐經(jīng)驗表明,處理的代碼的重要部分涉及密切相關(guān)的案例。因為設(shè)計人員和程序員十分專注于特殊案例,所以很難在這種系統(tǒng)中看到 “大局”。面向
7、對象編程提供 “透過樹木見森林” 的幾種方法。 </p><p> 程序員和設(shè)計人員專注于系統(tǒng)中對象的共性而不是特定實例,這種方法叫做抽象。 </p><p> 如果一個程序性方案有許多密切相關(guān)的案例,那么就會常用到switch交換結(jié)構(gòu)或嵌套的if / else結(jié)構(gòu)從而區(qū)分眾多的案例并提供獨立處理各個案例的邏輯。我們下面將學(xué)習(xí)如何使用繼承性和多態(tài)性以更簡單的邏輯來代替switch結(jié)構(gòu)
8、。我們區(qū)分“is a”關(guān)系和“has a”的關(guān)系。 “is a”就是繼承。在 “是”關(guān)系中,子類類型的對象也可以被看作是它的父類型的對象處理。 “有”是一種構(gòu)成。在“有”關(guān)系中,一個類對象有一個或多個其它類的對象作為成員。例如,車有方向盤。子類的方法可能需要確切訪問它的父類的實例變量和方法。在Java中,軟件工程的一個至關(guān)重要的方面就是子類不能訪問其父類的私有成員。如果子類可以訪問父類的私有成員,這就違背了父類的信息隱蔽原則。 <
9、/p><p> 然而,一個子類可以訪問它的父類的public成員和protected成員。如果子類和父類在同一個包中,子類也可以使用它的程序包訪問父類成員。如果超類不允許通過繼承產(chǎn)生的子類訪問它的某些成員,則需要用private聲明成員。子類只可以通過公有繼承、受保護繼承和程序包借助父類提供的繼承到子類中的方法聲明對父類中私有成員的改變。 </p><p> 繼承會帶來的問題是,子類會將一
10、些沒必要繼承或不該繼承方法也繼承過來。類的編寫者應(yīng)確保由類提供的功能對未來的子類是適用的。即使父類的方法對子類適用,子類也可以使該方法來完成特定于子類的方式的任務(wù)。在這種情況下,子類可以覆蓋超類的方法,以提供一種合適的實現(xiàn)。 </p><p> 也許最令人興奮的是一個新類可以從豐富的類庫中繼承,比如Java API提供許多類。 </p><p> 一些組織開發(fā)自己的類庫的同時還具有可以
11、利用現(xiàn)有的全球其他庫的優(yōu)勢。總有一天,大多數(shù)的軟件可以通過可重用的標準化的組件來構(gòu)建,就像現(xiàn)在制造硬件一樣。這將有助于面對開發(fā)我們將來可能需要的更加強大的軟件的挑戰(zhàn)。 </p><p> 我們常常會遇到這樣一個問題,一個類的對象同時還“是”另一個類的對象。矩形肯定是一個四邊形(如同正方形,平行四邊形和梯形)。因此,Rectangle 類可以說是從Quadrilateral類繼承而來的。在這種情況下,Quadri
12、lateral類是父類,Rectangle類是一個子類。矩形是特殊的四邊形,但卻不能說四邊形就是矩形(四邊形可能是平行四邊形)。 </p><p> 繼承通常能夠產(chǎn)生比其父類具有更多功能的子類,所以父類和子類的概念很容易引起混淆。然而,我們還有另種一更好的方法來區(qū)分這兩個概念。因為每個子類對象也“是”其父類的對象,而一個父類又可以有很多子類,那么由父類所代表的一組對象通常比由該對象的父類的任何子類所代表的要大
13、得多。例如,Vehicle超類包含了所有的交通工具,如汽車,卡車,船,自行車等。而Car子類僅表示交通工具Vehicle中的一個小子集。 </p><p> 繼承關(guān)系可以用樹型層次結(jié)構(gòu)來表示。一個父類與它的子類的構(gòu)成層次關(guān)系。一個類肯定可以獨自存在,但當(dāng)一個類是運用了繼承的機理時,這個類要么成為一個提供屬性和行為的父類,要么成為一個繼承這些屬性和行為的子類。通常情況下,一個類既是父類也是子類。 </p&g
14、t;<p> 一個子類的對象可以被當(dāng)作其父類的對象來處理。這使得可能會有一些有趣的操作。例如,盡管有從一個特定的父類派生出的眾多子類的對象彼此之間可能會有很大的不同的事實,但只要我們將他們當(dāng)作父類的對象來看,我們?nèi)钥梢詣?chuàng)建一個引用的數(shù)組給他們。但反之則不然:一個父類對象不能被當(dāng)成一個子類對象。例如,圖形(Shape)不一定是圓(Circle)。 </p><p> 盡管子類的對象也“是”父類的對
15、象,子類類型和父類類型卻是不相同的。子類對象可以被視為父類的對象。這是合理的,因為子類含有和每個超類成員相對應(yīng)的成員。但也應(yīng)認識到,子類通常擁有比父類更多的成員。但Java不允許逆向賦值,因為如果把超類對象賦給子類的引用,就會使子類中額外的子類成員沒有定義。 </p><p> 子類對象的引用可以被隱式地轉(zhuǎn)換為超類對象的引用,因為根據(jù)繼承性,子類對象“是”超類對象。 有四種可能的方法來使父類的對象和子類的對象與
16、父類的引用和子類的引用相匹配: </p><p> 1、父類對象與可以直接用父類的引用。 </p><p> 2、子類對象與可以直接用子類的引用。 </p><p> 3、子類的對象用父類的引用是安全的,因為子類對象同樣也是其父類的對象。但這樣的代碼只能引用父類的成員。如果該代碼通過父類的引用來訪問子類所特有的成員,編譯器就會報告一個語法錯誤。 <
17、/p><p> 4、如果用子類來引用父類的對象,將報告一個語法錯誤。 </p><p> 盡管將子類的對象看成是父類的對象會帶來很大的便利,而且可以通過這些父類的引用操縱這些對象來實現(xiàn),但這會引發(fā)一個問題。在一個工資管理系統(tǒng),例如,我們希望能夠通過一組員工數(shù)組來計算每個人的周薪。但是直覺告訴人們,使用父類的引用將使程序只調(diào)用父類的工資計算程序(如果父類中確實有這樣一個程序的話)。我們需要一
18、種方式僅通過使用父類的引用來正確的調(diào)用對每個對象(無論是父類對象或子類對象)相對應(yīng)的工資計算程序。其實,這正是當(dāng)我們考慮了多態(tài)性和動態(tài)鏈接后Java所呈現(xiàn)的并將在此章節(jié)中討論的內(nèi)容。 </p><p> 我們可以使用繼承來定制現(xiàn)有的軟件。當(dāng)我們使用繼承來從現(xiàn)有類創(chuàng)建一個新類時,新類將繼承的原有類的屬性和行為,此時我們可以添加屬性和行為或重載父類的行為來定制能滿足我們需要的類。 </p><p
19、> 很難讓學(xué)生意識到設(shè)計師和工業(yè)的大型軟件項目的實施者所面臨的問題。做過這類項目的人都會說提高軟件開發(fā)效率的最好方法是鼓勵對軟件的再利用。一般來說,面向?qū)ο蟮木幊?,像Java,就可以實現(xiàn)。 </p><p> 實質(zhì)和有用的類庫使得通過及繼承而實現(xiàn)的軟件重用實現(xiàn)利益最大化。人們對Java類庫的興趣隨著Java的發(fā)展而增加。正如獨立軟件廠商生產(chǎn)的壓縮套裝的軟件伴隨著個人電腦的問世而出現(xiàn)爆炸性的增長一樣,J
20、ava類庫的制造和銷售也將呈現(xiàn)這樣一個趨勢。應(yīng)用程序設(shè)計人員將使用這些類庫來構(gòu)建他們的應(yīng)用程序,而類庫的設(shè)計者會因為將其開發(fā)的類庫與應(yīng)用程序打包在一起而得到收益。在不久的將來,隨著在大量領(lǐng)域的應(yīng)用,Java的類庫將會起到至關(guān)重要的作用并得到極大的發(fā)展。</p><p> 附件2:外文原文(復(fù)印件)</p><p> Java Object-oriented programming &
21、lt;/p><p> --Object-oriented programming and its key component technologies as inheritance and polymorphism.</p><p> Software reusability saves time in program development. It encourages reuse of
22、 proven and debugged high-quality software, thus reducing problems after a system becomes operational. These are exciting possibilities. Polymorphism enables us to write programs in a general fashion to handle a wide var
23、iety of existing and yet-to-be-specified related classes.Polymorphism makes it easy to add new capabilities to a system. Inheritance and polym-orphism are effective techniques for dealing with software</p><p&
24、gt; Experience in building software systems indicates that significant portions of the code deal with closely related special cases. It becomes difficult in such systems to see the “big picture”because the designer and
25、the programmer become preoccupied with the special cases. Object-oriented programming provides several ways of “seeing the forest through the trees.” </p><p> The programmer and designer concentrate on the
26、big picture—the commonality among objects in the system—rather than the special cases. This process is called abstraction. </p><p> If a procedural program has many closely related special cases, then it is
27、 common to see switch structures or nested if/else structures that distinguish among the special cases and provide the processing logic to deal with each case individually. We will show how to use inheritance and polymor
28、phism to replace such switch logic with much simpler logic. We distinguish between the “is a” relationship and the “has a” relationship. “Is a” is inheritance. In an “is a” relationship, an object of a subc</p>&l
29、t;p> However, a subclass can access the public and protected members of its superclass. A subclass also can use the package access members of its superclass if the subclass and superclass are in the same package. Su
30、perclass members that should not be accessible to a subclass via inheritance are declared private in the superclass. A subclass can effect state changes in superclass private members only through public, protected and pa
31、ckage access methods provided in the superclass and inherited into th</p><p> A problem with inheritance is that a subclass can inherit methods that it does not need or should not have. It is the class desi
32、gner’s responsibility to ensure that the capabilities provided by a class are appropriate for future subclasses. Even when the superclass methods are appropriate for the subclasses, it is common for a subclass to require
33、 the method to perform a task in a manner that is specific to the subclass. In such cases, the superclass method can be overridden (redefined) in the su</p><p> Perhaps most exciting is the notion that new
34、classes can inherit from abundant class libraries, such as those provided with the Java API. </p><p> Organizations develop their own class libraries and can take advantage of other libraries available worl
35、dwide. Someday, most software might be constructed from standardized reusable components, just as hardware is often constructed today. This will help meet the challenges of developing the ever more powerful software we w
36、ill need in the future. </p><p> Often an object of one class “is an” object of another class as well. A rectangle certainly is a quadrilateral (as are squares, parallelograms and trapezoids). Thus, class
37、Rectangle can be said to inherit from class Quadrilateral. In this context, class Quadrilateral.is a superclass, and class Rectangle is a subclass. A rectangle is a specific type of quadrilateral, but it is incorrect to
38、claim that a quadrilateral is a rectangle (the quadrilateral could be a parallelogram). </p><p> Inheritance normally produces subclasses with more features than their superclasses, so the terms supercla
39、ss and subclass can be confusing. There is another way, however, to view these terms that makes perfectly good sense. Because every subclass object “is an”object of its superclass, and because one superclass can have man
40、y subclasses, the set of objects represented by a superclass is normally larger than the set of objects represented by any of that superclass’s subclasses. For example, the s</p><p> Inheritance relationshi
41、ps form tree-like hierarchical structures. A superclass exists in a hierarchical relationship with its subclasses. A class can certainly exist by itself, but it is when a class is used with the mechanism of inheritance t
42、hat the class becomes either a superclass that supplies attributes and behaviors to other classes or a subclass that inherits those attributes and behaviors. Frequently, one class is both a subclass and a superclass. <
43、;/p><p> An object of a subclass can be treated as an object of its superclass. This makes possible some interesting manipulations. For example, despite the fact that objects of a variety of classes derived fr
44、om a particular superclass might be quite different from one another, we can create an array of references to them—as long as we treat them as superclass objects. But the reverse is not true: A superclass object cannot a
45、lways be treated a subclass object. For example, a Shape is not always a Circle.</p><p> Despite the fact that a subclass object also “is a” superclass object, the subclass type and the superclass type are
46、different. Subclass objects can be treated as superclass objects. This makes sense because the subclass has members corresponding to each of the superclass members—remember that the subclass normally has more m
47、embers than the superclass has. Assignment in the other direction is not allowed because assigning a superclass object to a subclass reference would leave the addi</p><p> A reference to a subclass object c
48、ould be implicitly converted into a reference to a superclass object because a subclass object is a superclass object through inheritance. </p><p> There are four possible ways to mix and match superclass r
49、eferences and subclass references with superclass objects and subclass objects: </p><p> 1. Referring to a superclass object with a superclass reference is straightforward. </p><p>
50、2. Referring to a subclass object with a subclass reference is straightforward. </p><p> 3. Referring to a subclass object with a superclass reference is safe, because the subclass object is an object of it
51、s superclass as well. Such code can refer only to superclass members. If this code refers to subclass-only members through the superclass reference, the compiler will report a syntax error. </p><p> 4. Refe
52、rring to a superclass object with a subclass reference is a syntax error. </p><p> As convenient as it might be to treat subclass objects as superclass objects, and to do this by manipulating all these obje
53、cts with superclass references, there appears to be a problem. In a payroll system, for example, we would like to be able to walk through an array of employees and calculate the weekly pay for each person. But intuition
54、 suggests that using superclass references would enable the program to call only the superclass payroll calculation routine (if indeed there is such a routin</p><p> We can use inheritance to customize exis
55、ting software. When we use inheritance to create a new class from an existing class, the new class inherits the attributes and behaviors of an existing class; then we can add attributes and behaviors or override supercla
56、ss behaviors to customize the class to meet our needs. </p><p> It can be difficult for students to appreciate the problems faced by designers and implementers on large-scale software projects in industry.
57、People experienced on such projects will invariably state that a key to improving the software development process is encouraging software reuse. Object-oriented programming in general, and Java in particular, cer
58、tainly does this. </p><p> It is the availability of substantial and useful class libraries that delivers the maximum benefits of software reuse through inheritance. As interest in Java grows, interest in J
59、ava class libraries will increase. Just as shrink-wrapped software produced by independent software vendors became an explosive growth industry with the arrival of the personal computer, so, too, will the creation and sa
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- java的面向?qū)ο缶幊?-------課堂筆記
- java 編程外文翻譯
- java面向?qū)ο缶幊叹毩?xí)題答案
- java思想外文翻譯---java編程思想 (java和因特網(wǎng))
- 計算機專業(yè)外文資料翻譯--對象持久化和java-深入的了解面向?qū)ο笳Z言中的對象持久的討論
- 面向?qū)ο笤O(shè)計外文翻譯
- java面向?qū)ο罂偨Y(jié)
- 面向?qū)ο笤O(shè)計外文翻譯 (2)
- 面向?qū)ο笾型馕姆g
- 面向?qū)ο蟮膉ava語言練習(xí)
- 面向?qū)ο笈c圖形編程
- 計算機外文翻譯--java編程語言的介紹
- java面向?qū)ο蟮膶W(xué)習(xí)心得
- 《面向?qū)ο蟪绦蛟O(shè)計(java)》
- java面向?qū)ο罂碱}和答案
評論
0/150
提交評論