网络即时通信系统的设计 外文文献翻译Word下载.doc

上传人:聆听****声音 文档编号:433133 上传时间:2023-04-28 格式:DOC 页数:13 大小:59.50KB
下载 相关 举报
网络即时通信系统的设计 外文文献翻译Word下载.doc_第1页
第1页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第2页
第2页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第3页
第3页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第4页
第4页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第5页
第5页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第6页
第6页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第7页
第7页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第8页
第8页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第9页
第9页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第10页
第10页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第11页
第11页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第12页
第12页 / 共13页
网络即时通信系统的设计 外文文献翻译Word下载.doc_第13页
第13页 / 共13页
亲,该文档总共13页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

网络即时通信系统的设计 外文文献翻译Word下载.doc

《网络即时通信系统的设计 外文文献翻译Word下载.doc》由会员分享,可在线阅读,更多相关《网络即时通信系统的设计 外文文献翻译Word下载.doc(13页珍藏版)》请在冰点文库上搜索。

网络即时通信系统的设计 外文文献翻译Word下载.doc

本科毕业设计外文文献翻译

学生姓名:

学院:

信息工程学院

系别:

计算机系

专业:

软件工程

班级:

软件06

指导教师:

XXX讲师

     

二○一○年六月

本文源码索取,请联系qq:

XXX工业大学本科毕业设计外文文献翻译

Objectlandscapesandlifetimes

Technically,OOPisjustaboutabstractdatatyping,inheritance,andpolymorphism,butotherissuescanbeatleastasimportant.Theremainderofthissectionwillcovertheseissues.

Oneofthemostimportantfactorsisthewayobjectsarecreatedanddestroyed.Whereisthedataforanobjectandhowisthelifetimeoftheobjectcontrolled?

Therearedifferentphilosophiesatworkhere.C++takestheapproachthatcontrolofefficiencyisthemostimportantissue,soitgivestheprogrammerachoice.Formaximumrun-timespeed,thestorageandlifetimecanbedeterminedwhiletheprogramisbeingwritten,byplacingtheobjectsonthestack(thesearesometimescalledautomaticorscopedvariables)orinthestaticstoragearea.Thisplacesapriorityonthespeedofstorageallocationandrelease,andcontrolofthesecanbeveryvaluableinsomesituations.However,yousacrificeflexibilitybecauseyoumustknowtheexactquantity,lifetime,andtypeofobjectswhileyou'

rewritingtheprogram.Ifyouaretryingtosolveamoregeneralproblemsuchascomputer-aideddesign,warehousemanagement,orair-trafficcontrol,thisistoorestrictive.

Thesecondapproachistocreateobjectsdynamicallyinapoolofmemorycalledtheheap.Inthisapproach,youdon'

tknowuntilrun-timehowmanyobjectsyouneed,whattheirlifetimeis,orwhattheirexacttypeis.Thosearedeterminedatthespurofthemomentwhiletheprogramisrunning.Ifyouneedanewobject,yousimplymakeitontheheapatthepointthatyouneedit.Becausethestorageismanageddynamically,atrun-time,theamountoftimerequiredtoallocatestorageontheheapissignificantlylongerthanthetimetocreatestorageonthestack.(Creatingstorageonthestackisoftenasingleassemblyinstructiontomovethestackpointerdown,andanothertomoveitbackup.)Thedynamicapproachmakesthegenerallylogicalassumptionthatobjectstendtobecomplicated,sotheextraoverheadoffindingstorageandreleasingthatstoragewillnothaveanimportantimpactonthecreationofanobject.Inaddition,thegreaterflexibilityisessentialtosolvethegeneralprogrammingproblem.

Javausesthesecondapproach,exclusively].Everytimeyouwanttocreateanobject,youusethenewkeywordtobuildadynamicinstanceofthatobject.

There'

sanotherissue,however,andthat'

sthelifetimeofanobject.Withlanguagesthatallowobjectstobecreatedonthestack,thecompilerdetermineshowlongtheobjectlastsandcanautomaticallydestroyit.However,ifyoucreateitontheheapthecompilerhasnoknowledgeofitslifetime.InalanguagelikeC++,youmustdetermineprogrammaticallywhentodestroytheobject,whichcanleadtomemoryleaksifyoudon’tdoitcorrectly(andthisisacommonprobleminC++programs).Javaprovidesafeaturecalledagarbagecollectorthatautomaticallydiscoverswhenanobjectisnolongerinuseanddestroysit.Agarbagecollectorismuchmoreconvenientbecauseitreducesthenumberofissuesthatyoumusttrackandthecodeyoumustwrite.Moreimportant,thegarbagecollectorprovidesamuchhigherlevelofinsuranceagainsttheinsidiousproblemofmemoryleaks(whichhasbroughtmanyaC++projecttoitsknees).

Therestofthissectionlooksatadditionalfactorsconcerningobjectlifetimesandlandscapes.

1Collectionsanditerators

Ifyoudon’tknowhowmanyobjectsyou’regoingtoneedtosolveaparticularproblem,orhowlongtheywilllast,youalsodon’tknowhowtostorethoseobjects.Howcanyouknowhowmuchspacetocreateforthoseobjects?

Youcan’t,sincethatinformationisn’tknownuntilrun-time.

Thesolutiontomostproblemsinobject-orienteddesignseemsflippant:

youcreateanothertypeofobject.Thenewtypeofobjectthatsolvesthisparticularproblemholdsreferencestootherobjects.Ofcourse,youcandothesamethingwithanarray,whichisavailableinmostlanguages.Butthere’smore.Thisnewobject,generallycalledacontainer(alsocalledacollection,buttheJavalibraryusesthatterminadifferentsensesothisbookwilluse“container”),willexpanditselfwhenevernecessarytoaccommodateeverythingyouplaceinsideit.Soyoudon’tneedtoknowhowmanyobjectsyou’regoingtoholdinacontainer.Justcreateacontainerobjectandletittakecareofthedetails.

Fortunately,agoodOOPlanguagecomeswithasetofcontainersaspartofthepackage.InC++,it’spartoftheStandardC++LibraryandissometimescalledtheStandardTemplateLibrary(STL).ObjectPascalhascontainersinitsVisualComponentLibrary(VCL).Smalltalkhasaverycompletesetofcontainers.Javaalsohascontainersinitsstandardlibrary.Insomelibraries,agenericcontainerisconsideredgoodenoughforallneeds,andinothers(Java,forexample)thelibraryhasdifferenttypesofcontainersfordifferentneeds:

avector(calledanArrayListinJava)forconsistentaccesstoallelements,andalinkedlistforconsistentinsertionatallelements,forexample,soyoucanchoosetheparticulartypethatfitsyourneeds.Containerlibrariesmayalsoincludesets,queues,hashtables,trees,stacks,etc.

Allcontainershavesomewaytoputthingsinandgetthingsout;

thereareusuallyfunctionstoaddelementstoacontainer,andotherstofetchthoseelementsbackout.Butfetchingelementscanbemoreproblematic,becauseasingle-selectionfunctionisrestrictive.Whatifyouwanttomanipulateorcompareasetofelementsinthecontainerinsteadofjustone?

Thesolutionisaniterator,whichisanobjectwhosejobistoselecttheelementswithinacontainerandpresentthemtotheuseroftheiterator.Asaclass,italsoprovidesalevelofabstraction.Thisabstractioncanbeusedtoseparatethedetailsofthecontainerfromthecodethat’saccessingthatcontainer.Thecontainer,viatheiterator,isabstractedtobesimplyasequence.Theiteratorallowsyoutotraversethatsequencewithoutworryingabouttheunderlyingstructure—thatis,whetherit’sanArrayList,aLinkedList,aStack,orsomethingelse.Thisgivesyoutheflexibilitytoeasilychangetheunderlyingdatastructurewithoutdisturbingthecodeinyourprogram.Javabegan(inversion1.0and1.1)withastandarditerator,calledEnumeration,forallofitscontainerclasses.Java2hasaddedamuchmorecompletecontainerlibrarythatcontainsaniteratorcalledIteratorthatdoesmorethantheolderEnumeration.

Fromadesignstandpoint,allyoureallywantisasequencethatcanbemanipulatedtosolveyourproblem.Ifasingletypeofsequencesatisfiedallofyourneeds,there’dbenoreasontohavedifferentkinds.Therearetworeasonsthatyouneedachoiceofcontainers.First,containersprovidedifferenttypesofinterfacesandexternalbehavior.Astackhasadifferentinterfaceandbehaviorthanthatofaqueue,whichisdifferentfromthatofasetoralist.Oneofthesemightprovideamoreflexiblesolutiontoyourproblemthantheother.Second,differentcontainershavedifferentefficienciesforcertainoperations.ThebestexampleisanArrayListandaLinkedList.Botharesimplesequencesthatcanhaveidenticalinterfacesandexternalbehaviors.Butcertainoperationscanhaveradicallydifferentcosts.RandomlyaccessingelementsinanArrayListisaconstant-timeoperation;

ittakesthesameamountoftimeregardlessoftheelementyouselect.However,inaLinkedListitisexpensivetomovethroughthelisttorandomlyselectanelement,andittakeslongertofindanelementthatisfurtherdownthelist.Ontheotherhand,ifyouwanttoinsertanelementinthemiddleofasequence,it’smuchcheaperinaLinkedListthaninanArrayList.Theseandotheroperationshavedifferentefficienciesdependingontheunderlyingstructureofthesequence.Inthedesignphase,youmightstartwithaLinkedListand,whentuningforperformance,changetoanArrayList.Becauseoftheabstractionviaiterators,youcanchangefromonetotheotherwithminimalimpactonyourcode.

Intheend,rememberthatacontainerisonlyastoragecabinettoputobjectsin.Ifthatcabinetsolvesallofyourneeds,itdoesn’treallymatterhowitisimplemented(abasicconceptwithmosttypesofobjects).Ifyou’reworkinginaprogrammingenvironmentthathasbuilt-inoverheadduetootherfactors,thenthecostdifferencebetweenanArrayListandaLinkedListmightnotmatter.Youmightneedonlyonetypeofsequence.Youcanevenimaginethe“perfect”containerabstraction,whichcanautomaticallychangeitsunderlyingimplementationaccordingtothewayitisused.

2Thesinglyrootedhierarchy

OneoftheissuesinOOPthathasbecomeespeciallyprominentsincetheintroductionofC++iswhetherallclassesshouldultimatelybeinheritedfromasinglebaseclass.InJava(aswithvirtuallyallotherOOPlanguages)theansweris“yes”andthenameofthisultimatebaseclassissimplyObject.Itturnsoutthatthebenefitsofthesinglyrootedhierarchyaremany.

Allobjectsinasinglyrootedhierarchyhaveaninterfaceincommon,sotheyareallultimatelythesametype.Thealternative(providedbyC++)isthatyoudon’tknowthateverythingisthesamefundamentaltype.Fromabackward-compatibilitystandpointthisfitsthemodelofCbetterandcanbethoughtofaslessrestrictive,butwhenyouwanttodofull-onobject-orientedprogrammingyoumustthenbuildyourownhierarchytoprovidethesameconveniencethat’sbuiltintootherOOPlanguages.Andinanynewclasslibrary

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2