《运算机专业文献翻译》由会员分享,可在线阅读,更多相关《运算机专业文献翻译(38页珍藏版)》请在金锄头文库上搜索。
1、文献翻译ThinkinjavaAllprogramminglanguagesprovideabstractions.Itcanbearguedthatthecomplexityoftheproblemsyoureabletosolveisdirectlyrelatedtothekindandqualityofabstraction.By“kind1mean,“VChatisitthatyouareabstracting?”Assemblylanguageisasmallabstractionoftheunderlyingmachine.Manyso-calledaimperative,lang
2、uagesthatfollowed(suchasFORTRAN,BASIC,andC)wereabstractionsofassemblylanguage.Theselanguagesarcbigimprovementsoverassemblylanguage,buttheirprimaryabstractionstillrequiresyoutothinkintermsofthestructureofthecomputerratherthanthestructureoftheproblemyouarctryingtosolve.Theprogrammermustestablishtheass
3、ociationbetweenthemachinemodel(inthe“solutionspace/whichistheplacewhereyou,remodelingthatproblem,suchasacomputer)andthemodeloftheproblemthatisactuallybeingsolved(intheuproblemspace/whichistheplacewheretheproblemexists).Theeffortrequiredtoperformthismapping,andthefactthatitisextrinsictotheprogramming
4、language,producesprogramsthatarcdifficulttowriteandexpensivetomaintain,andasasideeffectcreatedtheentireprogrammingmethodsindustry.,Thealternativetomodelingthemachineistomodeltheproblemyouretryingtosolve.EarlylanguagessuchasLISPandAPLchoseparticularviewsoftheworld(AllproblemsarcultimatelylistsorAllpr
5、oblemsarcalgorithmic/respectively).PR()L()Gcastsallproblemsintochainsofdecisions.Languageshavebeencreatedforconstraint-basedprogrammingandforprogrammingexclusivelybymanipulatinggraphicalsymbols.(Thelatterprovedtobetoorestrictive.)Eachoftheseapproachesisagoodsolutiontotheparticularclassofproblemtheyr
6、edesignedtosolve,butwhenyoustepoutsideofthatdomainthevbecomeawkward.JTheobject-orientedapproachgoesastepfurtherbyprovidingtoolsfortheprogrammertorepresentelementsintheproblemspaceThisrepresentationisgeneralenoughthattheprogrammerisnotconstrainedtoallyparticulartypeofproblem.Werefertotheelementsinthe
7、problemspaceandtheirrepresentationsinthesolutionspaceas“objects.”(Youwillalsoneedotherobjectsthatdonthaveproblem-spaceanalogs.)Theideaisthattheprogramisallowedtoadaptitselftothelingooftheproblembyaddingnewtypesofobjects,sowhenyoureadthecodedescribingthesolution,yourereadingwordsthatalsoexpressthepro
8、blem.Thisisamoreflexibleandpowerfullanguageabstractionthanwhatwevchadbefore.Thus,OOPallowsyoutodescribetheproblemintermsoftheproblem,ratherthanintermsofthecomputerwherethesolutionwillrun.Theresstillaconnectionbacktothecomputer:eachobjectlooksquiteabitlikealittlecomputer-ithasastate,andithasoperation
9、sthatyoucanaskittoperform.However,thisdocsn,tseemlikesuchabadanalogytoobjectsintherealworld-theyallhavecharacteristicsandbehaviors.AlanKaysummarizedfivebasiccharacteristicsofSmalltalk,thefirstsuccessfulobject-orientedlanguageandoneofthelanguagesuponwhichJavaisbased.Thesecharacteristicsrepresentapure
10、approachtoobject-orientedprogramming:1. Everythingisanobject.Thinkofanobjectasafancyvariable;itstoresdata,butyoucan“makerequests“tothatobject,askingittoperformoperationsonitself.Intheory,youcantakeanyconceptualcomponentintheproblemyouretryingtosolve(dogs,buildings,services,etc.)andrepresentitasanobj
11、ectinyourprogram.2. Aprogramisabunchofobjectstellingeachotherwhattodobysendingmessages.Tomakearequestofanobject,youasendamessagewtothatobject.Moreconcretely,youcanthinkofamessageasarequesttocallamethodthatbelongstoaparticularobject3. Eachobjecthasitsownmemorymadeupofotherobjects.Putanotherway,youcre
12、ateanewkindofobjectbymakingapackagecontainingexistingobjects.Thus,youcanbuildcomplexityintoaprogramwhilehidingitbehindthesimplicityofobjects.4. Even-objecthasatype.Usingtheparlance,eachobjectisaninstanceofaclass,inwhich“classissynonymouswith“type.”Themostimportantdistinguishingcharacteristicofaclass
13、is“Whatmessagescanyousendtoit?”5. Allobjectsofaparticulartypecallreceivethesamemessages.Thisisactuallyaloadedstatement,asyouwillseclater.Becauseanobjectoftype“circle”isalsoanobjectoftypeshape:acircleisguaranteedtoacceptshapemessages.Thismeansyoucanwritecodethattalkstoshapesandautomaticallyhandleanyt
14、hingthatfitsthedescriptionofashape.ThissubscicutbilityisoneofthepowerfulconceptsinOOP.Boochoffersanevenmoresuccinctdescriptionofanobject:Anobjecthasstacc,behaviorandidentityThismeansthatailobjectcanhaveinternaldata(whichgivesitstate),methods(toproducebehavior),andeachobjectcanbeuniquelydistinguished
15、fromevery。由匚object-toputthisinaconcretesense,eachobjecthasauniqueaddressinmemory。AnobjecthasaninterfaceAristotlewasprobablythefirsttobeginacarefulstudyoftheconceptoftype;hespokeof“theclassoffishesandtheclassofbirds.Theideathatallobjects,whilebeingunique,arcalsopartofaclassofobjectsthathavecharacteri
16、sticsandbehaviorsincommonwasuseddirectlyinthefirstobject-orientedlanguage,Simula-67,withitsfundamentalkeywordclassthatintroducesanewtypeintoaprogram.Simula,asitsnameimplies,wascreatedfordevelopingsimulationssuchastheclassic“banktellerproblem.Inthis,youhaveabunchoftellers,customers,accounts,transactions,andunitsofmoneyalotof“objects.”Objectsthatarcidenticalexceptfortheirstateduringaprogramsexecutionarcgroupedtogetherintoaclassesofobjects”an