汇编语言对象入门中英文对照外文翻译文献.docx
《汇编语言对象入门中英文对照外文翻译文献.docx》由会员分享,可在线阅读,更多相关《汇编语言对象入门中英文对照外文翻译文献.docx(11页珍藏版)》请在冰点文库上搜索。
汇编语言对象入门中英文对照外文翻译文献
中英文资料外文翻译文献
1.IntroductionToObjects
1.1Theprogressofabstraction
Allprogramminglanguagesprovideabstractions.Itcanbearguedthatthecomplexityoftheproblemsyou’reabletosolveisdirectlyrelatedtothekindandqualityofabstraction.By“kind”Imean,“Whatisitthatyouareabstracting?
”Assemblylanguageisasmallabstractionoftheunderlyingmachine.Manyso-called“imperative”languagesthatfollowed(suchasFORTRAN,BASIC,andC)wereabstractionsofassemblylanguage.Theselanguagesarebigimprovementsoverassemblylanguage,buttheirprimaryabstractionstillrequiresyoutothinkintermsofthestructureofthecomputerratherthanthestructureoftheproblemyouaretryingtosolve.Theprogrammermustestablishtheassociationbetweenthemachinemodel(inthe“solutionspace,”whichistheplacewhereyou’remodelingthatproblem,suchasacomputer)andthemodeloftheproblemthatisactuallybeingsolved(inthe“problemspace,”whichistheplacewheretheproblemexists).Theeffortrequiredtoperformthismapping,andthefactthatitisextrinsictotheprogramminglanguage,producesprogramsthataredifficulttowriteandexpensivetomaintain,andasasideeffectcreatedtheentire“programmingmethods”industry.
Thealternativetomodelingthemachineistomodeltheproblemyou’retryingtosolve.EarlylanguagessuchasLISPandAPLchoseparticularviewsoftheworld(“Allproblemsareultimatelylists”or“Allproblemsarealgorithmic,”respectively).PROLOGcastsallproblemsintochainsofdecisions.Languageshavebeencreatedforconstraint-basedprogrammingandforprogrammingexclusivelybymanipulatinggraphicalsymbols.(Thelatterprovedtobetoorestrictive.)Eachoftheseapproachesisagoodsolutiontotheparticularclassofproblemthey’redesignedtosolve,butwhenyoustepoutsideofthatdomaintheybecomeawkward.
Theobject-orientedapproachgoesastepfurtherbyprovidingtoolsfortheprogrammertorepresentelementsintheproblemspace.Thisrepresentationisgeneralenoughthattheprogrammerisnotconstrainedtoanyparticulartypeofproblem.Werefertotheelementsintheproblemspaceandtheirrepresentationsinthesolutionspaceas“objects.”(Youwillalsoneedotherobjectsthatdon’thaveproblem-spaceanalogs.)Theideaisthattheprogramisallowedtoadaptitselftothelingooftheproblembyaddingnewtypesofobjects,sowhenyoureadthecodedescribingthesolution,you’rereadingwordsthatalsoexpresstheproblem.Thisisamoreflexibleandpowerfullanguageabstractionthanwhatwe’vehadbefore.Thus,OOPallowsyoutodescribetheproblemintermsoftheproblem,ratherthanintermsofthecomputerwherethesolutionwillrun.There’sstillaconnectionbacktothecomputer:
eachobjectlooksquiteabitlikealittlecomputer—ithasastate,andithasoperationsthatyoucanaskittoperform.However,thisdoesn’tseemlikesuchabadanalogytoobjectsintherealworld—theyallhavecharacteristicsandbehaviors.
AlanKaysummarizedfivebasiccharacteristicsofSmalltalk,thefirstsuccessfulobject-orientedlanguageandoneofthelanguagesuponwhichJavaisbased.Thesecharacteristicsrepresentapureapproachtoobject-orientedprogramming:
1.Everythingisanobject.Thinkofanobjectasafancyvariable;itstoresdata,butyoucan“makerequests”tothatobject,askingittoperformoperationsonitself.Intheory,youcantakeanyconceptualcomponentintheproblemyou’retryingtosolve(dogs,buildings,services,etc.)andrepresentitasanobjectinyourprogram.
2.Aprogramisabunchofobjectstellingeachotherwhattodobysendingmessages.Tomakearequestofanobject,you“sendamessage”tothatobject.Moreconcretely,youcanthinkofamessageasarequesttocallamethodthatbelongstoaparticularobject.
3.Eachobjecthasitsownmemorymadeupofotherobjects.Putanotherway,youcreateanewkindofobjectbymakingapackagecontainingexistingobjects.Thus,youcanbuildcomplexityintoaprogramwhilehidingitbehindthesimplicityofobjects.
4.Everyobjecthasatype.Usingtheparlance,eachobjectisaninstanceofaclass,inwhich“class”issynonymouswith“type.”Themostimportantdistinguishingcharacteristicofaclassis“Whatmessagescanyousendtoit?
”
5.Allobjectsofaparticulartypecanreceivethesamemessages.Thisisactuallyaloadedstatement,asyouwillseelater.Becauseanobjectoftype“circle”isalsoanobjectoftype“shape,”acircleisguaranteedtoacceptshapemessages.Thismeansyoucanwritecodethattalkstoshapesandautomaticallyhandleanythingthatfitsthedescriptionofashape.ThissubstitutabilityisoneofthepowerfulconceptsinOOP.
Boochoffersanevenmoresuccinctdescriptionofanobject:
Anobjecthasstate,behaviorandidentity.
Thismeansthatanobjectcanhaveinternaldata(whichgivesitstate),methods(toproducebehavior),andeachobjectcanbeuniquelydistinguishedfromeveryotherobject—toputthisinaconcretesense,eachobjecthasauniqueaddressinmemory.
1.2Anobjecthasaninterface
Aristotlewasprobablythefirsttobeginacarefulstudyoftheconceptoftype;hespokeof“theclassoffishesandtheclassofbirds.”Theideathatallobjects,whilebeingunique,arealsopartofaclassofobjectsthathavecharacteristicsandbehaviorsincommonwasuseddirectlyinthefirstobject-orientedlanguage,Simula-67,withitsfundamentalkeywordclassthatintroducesanewtypeintoaprogram.
Simula,asitsnameimplies,wascreatedfordevelopingsimulationssuchastheclassic“banktellerproblem.”Inthis,youhaveabunchoftellers,customers,accounts,transactions,andunitsofmoney—alotof“objects.”Objectsthatareidenticalexceptfortheirstateduringaprogram’sexecutionaregroupedtogetherinto“classesofobjects”andthat’swherethekeywordclasscamefrom.Creatingabstractdatatypes(classes)isafundamentalconceptinobject-orientedprogramming.Abstractdatatypesworkalmostexactlylikebuilt-intypes:
Youcancreatevariablesofatype(calledobjectsorinstancesinobject-orientedparlance)andmanipulatethosevariables(calledsendingmessagesorrequests;yousendamessageandtheobjectfiguresoutwhattodowithit).Themembers(elements)ofeachclasssharesomecommonality:
everyaccounthasabalance,everytellercanacceptadeposit,etc.Atthesametime,eachmemberhasitsownstate:
eachaccounthasadifferentbalance,eachtellerhasaname.Thus,thetellers,customers,accounts,transactions,etc.,caneachberepresentedwithauniqueentityinthecomputerprogram.Thisentityistheobject,andeachobjectbelongstoaparticularclassthatdefinesitscharacteristicsandbehaviors.
So,althoughwhatwereallydoinobject-orientedprogrammingiscreatenewdatatypes,virtuallyallobject-orientedprogramminglanguagesusethe“class”keyword.Whenyouseetheword“type”think“class”andviceversa.
Sinceaclassdescribesasetofobjectsthathaveidenticalcharacteristics(dataelements)andbehaviors(functionality),aclassisreallyadatatypebecauseafloatingpointnumber,forexample,alsohasasetofcharacteristicsandbehaviors.Thedifferenceisthataprogrammerdefinesaclasstofitaproblemratherthanbeingforcedtouseanexistingdatatypethatwasdesignedtorepresentaunitofstorageinamachine.Youextendtheprogramminglanguagebyaddingnewdatatypesspecifictoyourneeds.Theprogrammingsystemwelcomesthenewclassesandgivesthemallthecareandtype-checkingthatitgivestobuilt-intypes.
Theobject-orientedapproachisnotlimitedtobuildingsimulations.Whetherornotyouagreethatanyprogramisasimulationofthesystemyou’redesigning,theuseofOOPtechniquescaneasilyreducealargesetofproblemstoasimplesolution.
Onceaclassisestablished,youcanmakeasmanyobjectsofthatclassasyoulike,andthenmanipulatethoseobjectsasiftheyaretheelementsthatexistintheproblemyouaretryingtosolve.Indeed,oneofthechallengesofobject-orientedprogrammingistocreateaone-to-onemappingbetweentheelementsintheproblemspaceandobjectsinthesolutionspace.
Buthowdoyougetanobjecttodousefulworkforyou?
Theremustbeawaytomakearequestoftheobjectsothatitwilldosomething,suchascompleteatransaction,drawsomethingonthescreen,orturnonaswitch.Andeachobjectcansatisfyonlycertainrequests.Therequestsyoucanmakeofanobjectaredefinedbyitsinterface,andthetypeiswhatdeterminestheinterface.Asimpleexamplemightbearepresentationofalightbulb:
Light
On()
Off()
Lightlt=newLight();
lt.on();
Theinterfaceestablisheswhatrequestsyoucanmakeforaparticularobject.However,theremustbecodesomewheretosatisfythatrequest.This,alongwiththehiddendata,comprisestheimplementation.Fromaproceduralprogrammingstandpoint,it’snotthatcomplicated.Atypehasamethodassociatedwitheachpossiblerequest,andwhenyoumakeaparticularrequesttoanobject,thatmethodiscalled.Thisprocessisusuallysummarizedbysayingthatyou“sendamessage”(makearequest)toanobject,andtheobjectfiguresoutwhattodowiththatmessage(itexecutescode).
Here,thenameofthetype/classisLight,thenameofthisparticularLightobjectislt,andtherequeststhatyoucanmakeofaLightobjectaretoturniton,turnitoff,makeitbrighter,ormakeitdimmer.YoucreateaLightobjectbydefininga“reference”(lt)forthatobjectandcallingnewtorequestanewobjectofthattype.Tosendamessagetotheobject,youstatethenameoftheobjectandconnectitto