對(duì)象的創(chuàng)建和存在時(shí)間[外文文獻(xiàn)翻譯].doc
對(duì)象的創(chuàng)建和存在時(shí)間[外文文獻(xiàn)翻譯],英文:11809字中文:4864字object landscapes and lifetimestechnically, oop is just about abstract data typing, inheritance, and polymorphism, but other issues can be at l...
內(nèi)容介紹
此文檔由會(huì)員 果酸 發(fā)布英文:11809字
中文:4864字
Object landscapes and lifetimes
Technically, OOP is just about abstract data typing, inheritance, and polymorphism, but other issues can be at least as important. The remainder of this section will cover these issues.
One of the most important factors is the way objects are created and destroyed. Where is the data for an object and how is the lifetime of the object controlled? There are different philosophies at work here. C++ takes the approach that control of efficiency is the most important issue, so it gives the programmer a choice. For maximum run-time speed, the storage and lifetime can be determined while the program is being written, by placing the objects on the stack (these are sometimes called automatic or scoped variables) or in the static storage area. This places a priority on the speed of storage allocation and release, and control of these can be very valuable in some situations. However, you sacrifice flexibility because you must know the exact quantity, lifetime, and type of objects while you're writing the program. If you are trying to solve a more general problem such as computer-aided design, warehouse management, or air-traffic control, this is too restrictive.
對(duì)象的創(chuàng)建和存在時(shí)間
從技術(shù)角度說,OOP(面向?qū)ο蟪绦蛟O(shè)計(jì))只是涉及抽象的數(shù)據(jù)類型、繼承以及多形性,但另一些問題也可能顯得非常重要。本節(jié)將就這些問題進(jìn)行探討。
最重要的問題之一是對(duì)象的創(chuàng)建及破壞方式。對(duì)象需要的數(shù)據(jù)位于哪兒,如何控制對(duì)象的“存在時(shí)間”呢?針對(duì)這個(gè)問題,解決的方案是各異其趣的。C++認(rèn)為程序的執(zhí)行效率是最重要的一個(gè)問題,所以它允許程序員作出選擇。為獲得最快的運(yùn)行速度,存儲(chǔ)以及存在時(shí)間可在編寫程序時(shí)決定,只需將對(duì)象放置在堆棧(有時(shí)也叫作自動(dòng)或定域變量)或者靜態(tài)存儲(chǔ)區(qū)域即可。這樣便為存儲(chǔ)空間的分配和釋放提供了一個(gè)優(yōu)先級(jí)。某些情況下,這種優(yōu)先級(jí)的控制是非常有價(jià)值的。然而,我們同時(shí)也犧牲了靈活性,因?yàn)樵诰帉懗绦驎r(shí),必須知道對(duì)象的準(zhǔn)確的數(shù)量、存在時(shí)間、以及類型。如果要解決的是一個(gè)較常規(guī)的問題,如計(jì)算機(jī)輔助設(shè)計(jì)、倉儲(chǔ)管理或者空中交通控制,這一方法就顯得太局限了。
TA們正在看...
- 五年級(jí)下冊(cè)數(shù)學(xué)應(yīng)用題.doc
- 五年級(jí)信息技術(shù)上冊(cè)教案.doc
- 五年級(jí)信息技術(shù)教案.doc
- 五年級(jí)信息技術(shù)課程綱要.doc
- 五年級(jí)品德與社會(huì)課外綜合實(shí)踐活動(dòng)計(jì)劃.doc
- 五年級(jí)奧數(shù)-和倍問題.doc
- 五年級(jí)奧數(shù)倍數(shù)問題.doc
- 五年級(jí)奧數(shù)流水問題問題.doc
- 五年級(jí)奧數(shù)行程問題.doc
- 五年級(jí)家長會(huì)數(shù)學(xué)老師發(fā)言稿.doc