首页 软件工程外文文献翻译

软件工程外文文献翻译

举报
开通vip

软件工程外文文献翻译西安邮电学院毕业设计(论文)外文文献翻译院系:计算机学院专业:软件工程班级:软件0601学生姓名:导师姓名:职称:副教授起止时间:2010年3月8日至2010年6月11日ClassesOneofthemostcompellingfeaturesaboutJavaiscodereuse.Buttoberevolutionary,you’vegottobeabletodoalotmorethancopycodeandchangeit.That’stheapproachusedinprocedurallanguagesl...

软件工程外文文献翻译
西安邮电学院毕业设计( 论文 政研论文下载论文大学下载论文大学下载关于长拳的论文浙大论文封面下载 )外文文献翻译院系:计算机学院专业:软件 工程 路基工程安全技术交底工程项目施工成本控制工程量增项单年度零星工程技术标正投影法基本原理 班级:软件0601学生姓名:导师姓名:职称:副教授起止时间:2010年3月8日至2010年6月11日ClassesOneofthemostcompellingfeaturesaboutJavaiscodereuse.Buttoberevolutionary,you’vegottobeabletodoalotmorethancopycodeandchangeit.That’stheapproachusedinprocedurallanguageslikeC,andithasn’tworkedverywell.LikeeverythinginJava,thesolutionrevolvesaroundtheclass.Youreusecodebycreatingnewclasses,butinsteadofcreatingthemfromscratch,youuseexistingclassesthatsomeonehasalreadybuiltanddebugged.Thetrickistousetheclasseswithoutsoilingtheexistingcode.➢InitializingthebaseclassSincetherearenowtwoclassesinvolved—thebaseclassandthederivedclass—insteadofjustone,itcanbeabitconfusingtotrytoimaginetheresultingobjectproducedbyaderivedclass.Fromtheoutside,itlookslikethenewclasshasthesameinterfaceasthebaseclassandmaybesomeadditionalmethodsandfields.Butinheritancedoesn’tjustcopytheinterfaceofthebaseclass.Whenyoucreateanobjectofthederivedclass,itcontainswithinitasubobjectofthebaseclass.Thissubobjectisthesameasifyouhadcreatedanobjectofthebaseclassbyitself.It’sjustthatfromtheoutside,thesubobjectofthebaseclassiswrappedwithinthederived-classobject.Ofcourse,it’sessentialthatthebase-classsubobjectbeinitializedcorrectly,andthere’sonlyonewaytoguaranteethis:performtheinitializationintheconstructorbycallingthebase-classconstructor,whichhasalltheappropriateknowledgeandprivilegestoperformthebase-classinitialization.Javaautomaticallyinsertscallstothebase-classconstructorinthederived-classconstructor.➢GuaranteeingpropercleanupJavadoesn’thavetheC++conceptofadestructor,amethodthatisautomaticallycalledwhenanobjectisdestroyed.ThereasonisprobablythatinJava,thepracticeissimplytoforgetaboutobjectsratherthantodestroythem,allowingthegarbagecollectortoreclaimthememoryasnecessary.Oftenthisisfine,buttherearetimeswhenyourclassmightperformsomeactivitiesduringitslifetimethatrequirecleanup.AsmentionedinChapter4,youcan’tknowwhenthegarbagecollectorwillbecalled,orifitwillbecalled.Soifyouwantsomethingcleanedupforaclass,youmustexplicitlywriteaspecialmethodtodoit,andmakesurethattheclientprogrammerknowsthattheymustcallthismethod.Notethatinyourcleanupmethod,youmustalsopayattentiontothecallingorderforthebase-classandmember-objectcleanupmethodsincaseonesubobjectdependsonanother.Ingeneral,youshouldfollowthesameformthatisimposedbyaC++compileronitsdestructors:firstperformallofthecleanupworkspecifictoyourclass,inthereverseorderofcreation.(Ingeneral,thisrequiresthatbase-classelementsstillbeviable.)Thencallthebase-classcleanupmethod,asdemonstratedhere➢NamehidingIfaJavabaseclasshasamethodnamethat’soverloadedseveraltimes,redefiningthatmethodnameinthederivedclasswillnothideanyofthebase-classversions(unlikeC++).Thusoverloadingworksregardlessofwhetherthemethodwasdefinedatthislevelorinabaseclass,it’sfarmorecommontooverridemethodsofthesamename,usingexactlythesamesignatureandreturntypeasinthebaseclass.Itcanbeconfusingotherwise(whichiswhyC++disallowsit—topreventyoufrommakingwhatisprobablyamistake).➢Choosingcompositionvs.inheritanceBothcompositionandinheritanceallowyoutoplacesubobjectsinsideyournewclass(compositionexplicitlydoesthis—withinheritanceit’simplicit).Youmightwonderaboutthedifferencebetweenthetwo,andwhentochooseoneovertheother.Compositionisgenerallyusedwhenyouwantthefeaturesofanexistingclassinsideyournewclass,butnotitsinterface.Thatis,youembedanobjectsothatyoucanuseittoimplementfunctionalityinyournewclass,buttheuserofyournewclassseestheinterfaceyou’vedefinedforthenewclassratherthantheinterfacefromtheembeddedobject.Forthiseffect,youembedprivateobjectsofexistingclassesinsideyournewclass.Sometimesitmakessensetoallowtheclassusertodirectlyaccessthecompositionofyournewclass;thatis,tomakethememberobjectspublic.Thememberobjectsuseimplementationhidingthemselves,sothisisasafethingtodo.Whentheuserknowsyou’reassemblingabunchofparts,itmakestheinterfaceeasiertounderstand.Whenyouinherit,youtakeanexistingclassandmakeaspecialversionofit.Ingeneral,thismeansthatyou’retakingageneral-purposeclassandspecializingitforaparticularneed➢ThefinalkeywordJava’sfinalkeywordhasslightlydifferentmeaningsdependingonthecontext,butingeneralitsays“Thiscannotbechanged.”Youmightwanttopreventchangesfortworeasons:designorefficiency.Becausethesetworeasonsarequitedifferent,it’spossibletomisusethefinalkeywordThefollowingsectionsdiscussthethreeplaceswherefinalcanbeused:fordata,methods,andclasses.➢FinaldataManyprogramminglanguageshaveawaytotellthecompilerthatapieceofdatais“constant.”Aconstantisusefulfortworeasons:Itcanbeacompile-timeconstantthatwon’teverchange.Itcanbeavalueinitializedatruntimethatyoudon’twantchanged.Inthecaseofacompile-timeconstant,thecompilerisallowedto“fold”theconstantvalueintoanycalculationsinwhichit’sused;thatis,thecalculationcanbeperformedatcompiletime,eliminatingsomerun-timeoverhead.InJava,thesesortsofconstantsmustbeprimitivesandareexpressedwiththefinalkeyword.Avaluemustbegivenatthetimeofdefinitionofsuchaconstant.Afieldthatisbothstaticandfinalhasonlyonepieceofstoragethatcannotbechanged.Whenusingfinalwithobjectreferencesratherthanprimitives,themeaninggetsabitconfusing.Withaprimitive,finalmakesthevalueaconstant,butwithanobjectreference,finalmakesthereferenceaconstant.Oncethereferenceisinitializedtoanobject,itcanneverbechangedtopointtoanotherobject.However,theobjectitselfcanbemodified;Javadoesnotprovideawaytomakeanyarbitraryobjectaconstant.(Youcan,however,writeyourclasssothatobjectshavetheeffectofbeingconstant.)Thisrestrictionincludesarrays,whicharealsoobjects.➢FinalmethodsTherearetworeasonsforfinalmethods.Thefirstistoputa“lock”onthemethodtopreventanyinheritingclassfromchangingitsmeaning.Thisisdonefordesignreasonswhenyouwanttomakesurethatamethod’sbehaviorisretainedduringinheritanceandcannotbeoverridden.Thesecondreasonforfinalmethodsisefficiency.Ifyoumakeamethodfinal,youareallowingthecompilertoturnanycallstothatmethodintoinlinecalls.Whenthecompilerseesafinalmethodcall,itcan(atitsdiscretion)skipthenormalapproachofinsertingcodetoperformthemethodcallmechanism(pushargumentsonthestack,hopovertothemethodcodeandexecuteit,hopbackandcleanoffthestackarguments,anddealwiththereturnvalue)andinsteadreplacethemethodcallwithacopyoftheactualcodeinthemethodbody.Thiseliminatestheoverheadofthemethodcall.Ofcourse,ifamethodisbig,thenyourcodebeginstobloat,andyouprobablywon’tseeanyperformancegainsfrominlining,sinceanyimprovementswillbedwarfedbytheamountoftimespentinsidethemethod.ItisimpliedthattheJavacompilerisabletodetectthesesituationsandchoosewiselywhethertoinlineafinalmethod.However,it’sbesttoletthecompilerandJVMhandleefficiencyissuesandmakeamethodfinalonlyifyouwanttoexplicitlypreventoverriding➢FinalclassesWhenyousaythatanentireclassisfinal(byprecedingitsdefinitionwiththefinalkeyword),youstatethatyoudon’twanttoinheritfromthisclassorallowanyoneelsetodoso.Inotherwords,forsomereasonthedesignofyourclassissuchthatthereisneveraneedtomakeanychanges,orforsafetyorsecurityreasonsyoudon’twantsubclassingNotethatthefieldsofafinalclasscanbefinalornot,asyouchoose.ThesamerulesapplytofinalforfieldsregardlessofwhetHowever,becauseitpreventsinheritance,allmethodsinafinalclassareimplicitlyfinal,sincethere’snowaytooverridethem.Youcanaddthefinalspecifiertoamethodinafinalclass,butitdoesn’taddanymeaning.hertheclassisdefinedasfinal.SummaryBothinheritanceandcompositionallowyoutocreateanewtypefromexistingtypes.Typically,however,compositionreusesexistingtypesaspartoftheunderlyingimplementationofthenewtype,andinheritancereusestheinterface.Sincethederivedclasshasthebase-classinterface,itcanbeupcasttothebase,whichiscriticalforpolymorphism,asyou’llseeinthenextchapter.Despitethestrongemphasisoninheritanceinobject-orientedprogramming,whenyoustartadesignyoushouldgenerallyprefercompositionduringthefirstcutanduseinheritanceonlywhenitisclearlynecessary.Compositiontendstobemoreflexible.Inaddition,byusingtheaddedartificeofinheritancewithyourmembertype,youcanchangetheexacttype,andthusthebehavior,ofthosememberobjectsatruntime.Therefore,youcanchangethebehaviorofthecomposedobjectatruntime.Whendesigningasystem,yourgoalistofindorcreateasetofclassesinwhicheachclasshasaspecificuseandisneithertoobig(encompassingsomuchfunctionalitythatit’sunwieldytoreuse)norannoyinglysmall(youcan’tuseitbyitselforwithoutaddingfunctionality).类“Java引人注目的一项特性是代码的重复使用或者再生。但最具革命意义的是,除代码的复制和修改以外,我们还能做多得多的其他事情。”在象C那样的程序化语言里,代码的重复使用早已可行,但效果不是特别显著。与Java的其他地方一样,这个 方案 气瓶 现场处置方案 .pdf气瓶 现场处置方案 .doc见习基地管理方案.doc关于群访事件的化解方案建筑工地扬尘治理专项方案下载 解决的也是与类有关的问题。我们通过创建新类来重复使用代码,但却用不着重新创建,可以直接使用别人已建好并调试好的现成类。但这样做必须保证不会干扰原有的代码。➢初始化基础类由于这儿涉及到两个类——基础类及衍生类,而不再是以前的一个,所以在想象衍生类的结果对象时,可能会产生一些迷惑。从外部看,似乎新类拥有与基础类相同的接口,而且可包含一些额外的方法和字段。但继承并非仅仅简单地复制基础类的接口了事。创建衍生类的一个对象时,它在其中包含了基础类的一个“子对象”。这个子对象就象我们根据基础类本身创建了它的一个对象。从外部看,基础类的子对象已封装到衍生类的对象里了。当然,基础类子对象应该正确地初始化,而且只有一种方法能保证这一点:在构建器中执行初始化,通过调用基础类构建器,后者有足够的能力和权限来执行对基础类的初始化。在衍生类的构建器中,Java会自动插入对基础类构建器的调用。➢确保正确的清除Java不具备象C++的“破坏器”那样的概念。在C++中,一旦破坏(清除)一个对象,就会自动调用破坏器方法。之所以将其省略,大概是由于在Java中只需简单地忘记对象,不需强行破坏它们。垃圾收集器会在必要的时候自动回收内存。垃圾收集器大多数时候都能很好地工作,但在某些情况下,我们的类可能在自己的存在时期采取一些行动,而这些行动要求必须进行明确的清除工作。正如第4章已经指出的那样,我们并不知道垃圾收集器什么时候才会显身,或者说不知它何时会调用。所以一旦希望为一个类清除什么东西,必须写一个特别的方法,明确、专门地来做这件事情。同时,还要让客户程序员知道他们必须调用这个方法。在自己的清除方法中,必须注意对基础类以及成员对象清除方法的调用顺序——假若一个子对象要以另一个为基础。通常,应采取与C++编译器对它的“破坏器”采取的同样的形式:首先完成与类有关的所有特殊工作(可能要求基础类元素仍然可见),然后调用基础类清除方法,就象这儿演示的那样。许多情况下,清除可能并不是个问题;只需让垃圾收集器尽它的职责即可。但一旦必须由自己明确清除,就必须特别谨慎,并要求周全的考虑。
本文档为【软件工程外文文献翻译】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_270070
暂无简介~
格式:pdf
大小:263KB
软件:PDF阅读器
页数:7
分类:
上传时间:2020-05-18
浏览量:4