![計(jì)算機(jī)專業(yè)英語chapter-2-programming-language課件_第1頁](http://file4.renrendoc.com/view/a7492fe19bf152a0bc8f71b46e69680c/a7492fe19bf152a0bc8f71b46e69680c1.gif)
![計(jì)算機(jī)專業(yè)英語chapter-2-programming-language課件_第2頁](http://file4.renrendoc.com/view/a7492fe19bf152a0bc8f71b46e69680c/a7492fe19bf152a0bc8f71b46e69680c2.gif)
![計(jì)算機(jī)專業(yè)英語chapter-2-programming-language課件_第3頁](http://file4.renrendoc.com/view/a7492fe19bf152a0bc8f71b46e69680c/a7492fe19bf152a0bc8f71b46e69680c3.gif)
![計(jì)算機(jī)專業(yè)英語chapter-2-programming-language課件_第4頁](http://file4.renrendoc.com/view/a7492fe19bf152a0bc8f71b46e69680c/a7492fe19bf152a0bc8f71b46e69680c4.gif)
![計(jì)算機(jī)專業(yè)英語chapter-2-programming-language課件_第5頁](http://file4.renrendoc.com/view/a7492fe19bf152a0bc8f71b46e69680c/a7492fe19bf152a0bc8f71b46e69680c5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
chapter2programminglanguage2.1ComputerProgramAcomputerprogramisasetofinstructionsthatdirectsacomputertoperformsomeprocessingfunctionorcombinationoffunctions.Fortheinstructionstobecarriedout,acomputermustexecuteaprogram,thatis,thecomputerreadstheprogram,andthenfollowsthestepsencodedintheprograminapreciseorderuntilcompletion.Aprogramcanbeexecutedmanydifferenttimes,witheachexecutionyieldingapotentiallydifferentresultdependingupontheoptionsanddatathattheusergivesthecomputer.Programsfallintotwomajorclasses:applicationprogramsandoperatingsystems.Withthetexteditor,theprogrammercreatesatextfile,whichisanorderedlistofinstructions,alsocalledtheprogramsourcefile.Theindividualinstructionsthatmakeuptheprogramsourcefilearecalledsourcecode.Atthispoint,aspecialapplicationsprogramtranslatesthesourcecodeintomachinelanguage,orobjectcode—aformatthattheoperatingsystemwillrecognizeasaproperprogramandbeabletoexecute.Threetypesofapplicationsprogramstranslatefromsourcecodetoobjectcode:compilers,interpreters,andassemblers.Thethreeoperatedifferentlyandondifferenttypesofprogramminglanguages,buttheyservethesamepurposeoftranslatingfromaprogramminglanguageintomachinelanguage.Acompilertranslatestextfileswritteninahigh-levelprogramminglanguage—suchasFORTRAN,C,orPascal—fromthesourcecodetotheobjectcodeallatonce.ThisdiffersfromtheapproachtakenbyinterpretedlanguagessuchasBASIC,inwhichaprogramistranslatedintoobjectcodestatementbystatementaseachinstructionisexecuted.Theadvantageofinterpretedlanguagesisthattheycanbeginexecutingtheprogramimmediatelyinsteadofhavingtowaitforallofthesourcecodetobecompiled.Changescanalsobemadetotheprogramfairlyquicklywithouthavingtowaitforittobecompiledagain.Thedisadvantageofinterpretedlanguagesisthattheyareslowtoexecute,sincetheentireprogrammustbetranslatedoneinstructionatatime,eachtimetheprogramisrun.Ontheotherhand,compiledlanguagesarecompiledonlyonceandthuscanbeexecutedbythecomputermuchmorequicklythaninterpretedlanguages.Forthisreason,compiledlanguagesaremorecommonandarealmostalwaysusedinprofessionalandscientificapplications.
Anothertypeoftranslatoristheassembler,whichisusedforprogramsorpartsofprogramswritteninassemblylanguage.Assemblylanguageisanotherprogramminglanguage,butitismuchmoresimilartomachinelanguagethanothertypesofhigh-levellanguages.Inassemblylanguage,asinglestatementcanusuallybetranslatedintoasingleinstructionofmachinelanguage.Today,assemblylanguageisrarelyusedtowriteanentireprogram,butisinsteadmostoftenusedwhentheprogrammerneedstodirectlycontrolsomeaspectofthecomputer’sfunction.
Programsareoftenwrittenasasetofsmallerpieces,8witheachpiecerepresentingsomeaspectoftheoverallapplicationprogram.Aftereachpiecehasbeencompiledseparately,aprogramcalledalinkercombinesallofthetranslatedpiecesintoasingleexecutableprogram.Programsseldomworkcorrectlythefirsttime,soaprogramcalledadebuggerisoftenusedtohelpfindproblemscalledbugs.Debuggingprogramsusuallydetectaneventintheexecutingprogramandpointtheprogrammerbacktotheoriginoftheeventintheprogramcode.Recentprogrammingsystems,suchasJava,useacombinationofapproachestocreateandexecuteprograms.AcompilertakesaJavasourceprogramandtranslatesitintoanintermediateform.SuchintermediateprogramsarethentransferredovertheInternetintocomputerswhereaninterpreterprogramthenexecutestheintermediateformasanapplicationprogram.Ⅱ.ProgramElementsMostprogramsarebuiltfromjustafewkindsofstepsthatarerepeatedmanytimesindifferentcontextsandindifferentcombinationsthroughouttheprogram.Themostcommonstepperformssomecomputation,andthenproceedstothenextstepintheprogram,intheorderspecifiedbytheprogrammer.Programsoftenneedtorepeatashortseriesofstepsmanytimes,forinstanceinlookingthroughalistofgamescoresandfindingthehighestscore.Suchrepetitivesequencesofcodearecalledloops.Oneofthecapabilitiesthatmakecomputerssousefulistheirabilitytomakeconditionaldecisionsandperformdifferentinstructionsbasedonthevaluesofdatabeingprocessed.If-then-elsestatementsimplementthisfunctionbytestingsomepieceofdataandthenselectingoneoftwosequencesofinstructionsonthebasisoftheresult.Oneoftheinstructionsinthesealternativesmaybeagotostatementthatdirectsthecomputertoselectitsnextinstructionfromadifferentpartoftheprogram.Forexample,aprogrammightcomparetwonumbersandbranchtoadifferentpartoftheprogramdependingontheresultofthecomparison:ifxisgreatthanythengotoinstruction#10elsecontinueProgramsoftenuseaspecificsequenceofstepsmorethanonce.Suchasequenceofstepscanbegroupedtogetherintoasubroutine,whichcanthenbecalled,oraccessed,asneededindifferentpartsofthemainprogram.Eachtimeasubroutineiscalled,thecomputerrememberswhereitwasintheprogramwhenthecallwasmade,sothatitcanreturnthereuponcompletionofthesubroutine.Eachtimeasubroutineiscalled,thecomputerrememberswhereitwasintheprogramwhenthecallwasmade,sothatitcanreturnthereuponcompletionofthesubroutine.Precedingeachcall,aprogramcanspecifythatdifferentdatabeusedbythesubroutine,allowingaverygeneralpieceofcodetobewrittenonceandusedinmultipleways.ProgramFunctionMostprogramsuseseveralvarietiesofsubroutines.Themostcommonofthesearefunctions,procedures,libraryroutines,systemroutines,anddevicedrivers.Functionsareshortsubroutinesthatcomputesomevalue,suchascomputationsofangles,whichthecomputercannotcomputewithasinglebasicinstruction.Proceduresperformamorecomplexfunction,suchassortingasetofnames.Libraryroutinesaresubroutinesthatarewrittenforusebymanydifferentprograms.Systemroutinesaresimilartolibraryroutinesbutareactuallyfoundintheoperatingsystem.Theyprovidesomeservicefortheapplicationprograms,suchasprintingalineoftext.Devicedriversaresystemroutinesthatareaddedtoanoperatingsystemtoallowthecomputertocommunicatewithanewdevice,suchasascanner,modem,orprinter.Devicedriversoftenhavefeaturesthatcanbeexecuteddirectlyasapplicationsprograms.Thisallowstheusertodirectlycontrolthedevice,whichisusefulif,forinstance,acolorprinterneedstoberealignedtoattainthebestprintingqualityafterchanginganinkcartridge.Ⅲ.ProgramFunctionModerncomputersusuallystoreprogramsonsomeformofmagneticstoragemediathatcanbeaccessedrandomlybythecomputer,suchastheharddrivediskpermanentlylocatedinthecomputer,oraportablefloppydisk.Additionalinformationonsuchdisks,calleddirectories,indicatesthenamesofthevariousprogramsonthedisk,whentheywerewrittentothedisk,andwheretheprogrambeginsonthediskmedia.Whenauserdirectsthecomputertoexecuteaparticularapplicationprogram,theoperatingsystemlooksthroughthesedirectories,locatestheprogram,andreadsacopyintoRAM.TheoperatingsystemthendirectstheCPU(centralprocessingunit)tostartexecutingtheinstructionsatthebeginningoftheprogram.InstructionsatthebeginningoftheprogrampreparethecomputertoprocessinformationbylocatingfreememorylocationsinRAMtoholdworkingdata,retrievingcopiesofthestandardoptionsanddefaultstheuserhasindicatedfromadisk,anddrawinginitialdisplaysonthemonitor.Theoperatingsystemconvertsanydatasoenteredintoastandardinternalform.Theapplicationthenusesthisinformationtodecidewhattodonext—forexample,performsomedesiredprocessingfunctionsuchasreformattingapageoftext,orobtainsomeadditionalinformationfromanotherfileonadisk.Ineithercase,callstoothersystemroutinesareusedtoactuallycarryoutthedisplayoftheresultsortheaccessingofthefilefromthedisk.Whentheapplicationreachescompletionorispromptedtoquit,itmakesfurthersystemcallstomakesurethatalldatathatneedstobesavedhasbeenwrittenbacktodisk.Itthenmakesafinalsystemcalltotheoperatingsystemindicatingthatitisfinished.TheoperatingsystemthenfreesuptheRAMandanydevicesthattheapplicationwasusingandawaitsacommandfromtheusertostartanotherprogram.Ⅳ.HistoryPeoplehavebeenstoringsequencesofinstructionsintheformofaprogramforseveralcenturies.Musicboxesofthe18thcenturyandplayerpianosofthelate19thandearly20thcenturiesplayedmusicalprogramsstoredasseriesofmetalpins,orholesinpaper,witheachline(ofpinsorholes)representingwhenanotewastobeplayed,andthepinorholeindicatingwhatnotewastobeplayedatthattime.Moreelaboratecontrolofphysicaldevicesbecamecommonintheearly1800swithFrenchinventorJosephMarieJacquard’sinventionofthepunch-cardcontrolledweavingloom.Intheprocessofweavingaparticularpattern,variouspartsoftheloomhadtobemechanicallypositioned.Toautomatethisprocess,Jacquardusedasinglepapercardtorepresenteachpositioningoftheloom,withholesinthecardtoindicatewhichloomactionsshouldbedone.Anentiretapestrycouldbeencodedontoadeckofsuchcards,withthesamedeckyieldingthesametapestrydesigneachtimeitwasused.Programsofover24,000cardsweredevelopedandused.Theworld’sfirstprogrammablemachinewasdesigned—althoughneverfullybuilt—bytheEnglishmathematicianandinventor,CharlesBabbage.Thismachine,calledtheAnalyticalEngine,usedpunchcardssimilartothoseusedintheJacquardloomtoselectthespecificarithmeticoperationtoapplyateachstep.Theworld’sfirstprogrammablemachinewasdesigned—althoughneverfullybuilt—bytheEnglishmathematicianandinventor,CharlesBabbage.Thismachine,calledtheAnalyticalEngine,usedpunchcardssimilartothoseusedintheJacquardloomtoselectthespecificarithmeticoperationtoapplyateachstep.ThefirstcarddeckprogramsfortheAnalyticalEngineweredevelopedbyBritishmathematicianAugustaAdaByron,daughterofthepoetLordByron.Forthisreasonsheisrecognizedastheworld’sfirstprogrammer.VonNeumann’sideawastousethecomputer’smemorytostoretheprogramaswellasthedata.Inthisway,programscanbeviewedasdataandcanbeprocessedlikedatabyotherprograms.Thisideagreatlysimplifiestheroleofprogramstorageandexecutionincomputers.Thefieldofcomputersciencehasgrownrapidlysincethe1950sduetotheincreaseintheiruse.Computerprogramshaveundergonemanychangesduringthistimeinresponsetouserneedandadvancesintechnology.Newerideasincomputingsuchasparallelcomputing,distributedcomputing,andartificialintelligence,haveradicallyalteredthetraditionalconceptsthatoncedeterminedprogramformandfunction.Ⅴ.TheFuture
Computerscientistsworkinginthefieldofparallelcomputing,inwhichmultipleCPUscooperateonthesameproblematthesametime,haveintroducedanumberofnewprogrammodels.Inparallelcomputingpartsofaproblemareworkedonsimultaneouslybydifferentprocessors,andthisspeedsupthesolutionoftheproblem.Manychallengesfacescientistsandengineerswhodesignprogramsforparallelprocessingcomputers,becauseoftheextremecomplexityofthesystemsandthedifficultyinvolvedinmakingthemoperateaseffectivelyaspossible.AnothertypeofparallelcomputingcalleddistributedcomputingusesCPUsfrommanyinterconnectedcomputerstosolveproblems.OftenthecomputersusedtoprocessinformationinadistributedcomputingapplicationareconnectedovertheInternet.Internetapplicationsarebecomingaparticularlyusefulformofdistributedcomputing,especiallywithprogramminglanguagessuchasJava.Insuchapplications,auserlogsontoaWebsiteanddownloadsaJavaprogramontotheircomputer.WhentheJavaprogramisrun,itcommunicateswithotherprogramsatitshomeWebsite,andmayalsocommunicatewithotherprogramsrunningondifferentcomputersorWebsites.Researchintoartificialintelligence(AI)hasledtoseveralothernewstylesofprogramming.Logicprograms,forexample,donotconsistofindividualinstructionsforthecomputertofollowblindly,butinsteadconsistofsetsofrules:ifxhappensthendoy.Aspecialprogramcalledaninferenceengineusestheserulesto“reason”itswaytoaconclusionwhenpresentedwithanewproblem.Applicationsoflogicprogramsincludeautomaticmonitoringofcomplexsystems,andprovingmathematicaltheorems.Aradicallydifferentapproachtocomputinginwhichthereisnoprogramintheconventionalsenseiscalledaneuralnetwork.Aneuralnetworkisagroupofhighlyinterconnectedsimpleprocessingelements,designedtomimicthebrain.Insteadofhavingaprogramdirecttheinformationprocessinginthewaythatatraditionalcomputerdoes,aneuralnetworkprocessesinformationdependinguponthewaythatitsprocessingelementsareconnected.Programminganeuralnetworkisaccomplishedbypresentingitwithknownpatternsofinputandoutputdataandadjustingtherelativeimportanceoftheinterconnectionsbetweentheprocessingelementsuntilthedesiredpatternmatchingisaccomplished.18Neuralnetworksareusuallysimulatedontraditionalcomputers,butunliketraditionalcomputerprograms,neuralnetworksareabletolearnfromtheirexperience.2.2IntroductionofprogramminglanguagesAprogramminglanguageisanartificiallanguagedesignedtocommunicateinstructionstoamachine,particularlyacomputer.Programminglanguagescanbeusedtocreateprogramsthatcontrolthebehaviorofamachineand/ortoexpressalgorithmsprecisely.Similartonaturallanguages,suchasEnglish,programminglanguageshaveavocabulary,grammar,andsyntax.However,naturallanguagesarenotsuitedforprogrammingcomputersbecausetheyareambiguous,meaningthattheirvocabularyandgrammaticalstructuremaybeinterpretedinmultipleways.Thelanguagesusedtoprogramcomputersmusthavesimplelogicalstructures,andtherulesfortheirgrammar,spelling,andpunctuationmustbeprecise.Ⅰ.DefinitionsAprogramminglanguageisanotationforwritingprograms,whicharespecificationsofacomputationoralgorithm.Some,butnotall,authorsrestricttheterm"programminglanguage"tothoselanguagesthatcanexpressallpossiblealgorithms.Traitsoftenconsideredimportantforwhatconstitutesaprogramminglanguageinclude:Functionandtarget:Acomputerprogramminglanguageisalanguageusedtowritecomputerprograms,whichinvolveacomputerperformingsomekindofcomputationoralgorithmandpossiblycontrolexternaldevicessuchasprinters,diskdrives,robots,andsoon.ForexamplePostScriptprogramsarefrequentlycreatedbyanotherprogramtocontrolacomputerprinterordisplay.Moregenerally,aprogramminglanguagemaydescribecomputationonsome,possiblyabstract,machine.Itisgenerallyacceptedthatacompletespecificationforaprogramminglanguageincludesadescription,possiblyidealized,ofamachineorprocessorforthatlanguage.Inmostpracticalcontexts,aprogramminglanguageinvolvesacomputer;consequently,programminglanguagesareusuallydefinedandstudiedthisway.Programminglanguagesdifferfromnaturallanguagesinthatnaturallanguagesareonlyusedforinteractionbetweenpeople,whileprogramminglanguagesalsoallowhumanstocommunicateinstructionstomachines.Abstractions:Programminglanguagesusuallycontainabstractionsfordefiningandmanipulatingdatastructuresorcontrollingtheflowofexecution.Thepracticalnecessitythataprogramminglanguagesupportadequateabstractionsisexpressedbytheabstractionprinciple;thisprincipleissometimesformulatedasrecommendationtotheprogrammertomakeproperuseofsuchabstractions.Expressivepower:Thetheoryofcomputationclassifieslanguagesbythecomputationstheyarecapableofexpressing.AllTuringcompletelanguagescanimplementthesamesetofalgorithms.ANSI/ISOSQLandCharityareexamplesoflanguagesthatarenotTuringcomplete,yetoftencalledprogramminglanguages.Themostcommonlyusedprogramminglanguagesarehighlyportableandcanbeusedtoeffectivelysolvediversetypesofcomputingproblems.LanguageslikeC,PASCAL,andBASICfallintothiscategory.Programminglanguagesmaybedividedintothreegeneraltypes:Low-levelprogramminglanguagesHigh-levellanguagesAssemblyLanguagesⅡ.LanguageTypes1.Low-levelprogramminglanguages,ormachinelanguages,arethemostbasictypeofprogramminglanguagesandcanbeunderstooddirectlybyacomputer.Machinelanguageisthe“naturallanguage”ofaparticularcomputer.Itisdefinedbythehardwaredesignofthecomputer.Inmachinelanguages,instructionsarewrittenassequencesof1sand0s,calledbits,thatacomputercanunderstanddirectly.Aninstructioninmachinelanguagegenerallytellsthecomputerfourthings:Wheretofindoneortwonumbersorsimplepiecesofdatainthemaincomputermemory(RandomAccessMemory,orRAM),Asimpleoperationtoperform,suchasaddingthetwonumberstogether,Whereinthemainmemorytoputtheresultofthissimpleoperation,Wheretofindthenextinstructiontoperform.Whileallexecutableprogramsareeventuallyreadbythecomputerinmachinelanguage,theyarenotallprogrammedinmachinelanguage.Itisextremelydifficulttoprogramdirectlyinmachinelanguagebecausetheinstructionsaresequencesof1sand0s.Atypicalinstructioninamachinelanguagemightread1001011001011andmeansaddingthecontentsofstorageregisterAtothecontentsofstorageregisterB.2."High-levellanguage"referstothehigherlevelofabstractionfrommachinelanguage.Ratherthandealingwithregisters,memoryaddressesandcallstacks,high-levellanguagesdealwithvariables,arrays,objects,complexarithmeticorbooleanexpressions,subroutinesandfunctions,loops,threads,locks,andotherabstractcomputerscienceconcepts,withafocusonusabilityoveroptimalprogramefficiency.Unlikelow-levelassemblylanguages,high-levellanguageshavefew,ifany,languageelementsthattranslatedirectlyintoamachine'snativecodes.Otherfeatures,suchasstringhandlingroutines,object-orientedlanguagefeatures,andfileinput/output,mayalsobepresent.High-levellanguagesarerelativelysophisticatedsetsofstatementsutilizingwordsandsyntaxfromhumanlanguage21.Theyaremoresimilartonormalhumanlanguagesthanassemblyormachinelanguagesandarethereforeeasiertouseforwritingcomplicatedprograms.Theseprogramminglanguagesallowlargerandmorecomplicatedprogramstobedevelopedfaster.However,high-levellanguagesmustbetranslatedintomachinelanguagebyanotherprogramcalledacompilerbeforeacomputercanunderstandthem.Forthisreason,programswritteninahigh-levellanguagemaytakelongertoexecuteanduseupmorememorythanprogramswritteninanassemblylanguage.3.Assemblylanguageisalow-levelprogramminglanguageforcomputers,microprocessors,microcontrollers,andotherprogrammabledevicesinwhicheachstatementcorrespondstoasinglemachinelanguageinstruction.Anassemblylanguageisspecifictoacertaincomputerarchitecture,incontrasttomosthigh-levelprogramminglanguages,whichgenerallyareportabletomultiplesystems.Assemblylanguageprogramsareconvertedintoexecutablemachinecodebyautilityprogramreferredtoasanassembler,theconversionprocessbeingreferredtoasassemblyorassemblingtheprogram.Assemblylanguageusesmnemonicstorepresentthelow-levelmachineoperationsthatareuniquetothetargetsystem.Dependingontheparticularinstructionbeingassembled,anoperandmaybepartoftheinstruction.Mostassemblersalsounderstandtheuseoflabelsandsymbolstorepresentaddressesandconstants,makingitpossibletosymbolicallyrepresentoperandsinsteadofenteringhardcodeddata.Generallyspeaking,thereisaone–to–onecorrespondencebetweeneachassemblylanguagestatementandanexecutablemachineinstruction.Actually,inanassemblylanguage,eachstatementcorresponds
roughlytoonemachinelanguageinstruction.Anassemblylanguagestatementiscomposedwiththeaidofeasytoremembercommands.ThecommandtoaddthecontentsofthestorageregisterAtothecontentsofstorageregisterBmightbewrittenADDB,Ainatypicalassemblylanguagestatement.Assemblylanguagessharecertainfeatureswithmachinelanguages.Forinstance,itispossibletomanipulatespecificbitsinbothassemblyandmachinelanguages22.Programmersuseassemblylanguageswhenitisimportanttominimizethetimeittakestorunaprogram,becausethetranslationfromassemblylanguagetomachinelanguageisrelativelysimple.Assemblylanguagesarealsousedwhensomepartofthecomputerhastobecontrolleddirectly,suchasindividualdotsonamonitorortheflowofindividualcharacterstoaprinter.Ⅲ.ClassificationofHigh-LevelLanguagesHigh-levellanguagesarecommonlyclassifiedasprocedure-oriented,functional,object-oriented,orlogiclanguages.Inprocedure-orientedlanguages,oneormorerelatedblocksofstatementsthatperformsomecompletefunctionaregroupedtogetherintoaprogrammodule,orprocedure,andgivenanamesuchas“procedureA”.Ifthesamesequenceofoperationsisneededelsewhereintheprogram,asimplestatementcanbeusedtoreferbacktotheprocedure.Inessence,aprocedureisjustamini-program.Alargeprogramcanbeconstructedbygroupingtogetherproceduresthatperformdifferenttasks.Procedurallanguagesallowprogramstobeshorterandeasierforthecomputertoread,buttheyrequiretheprogrammertodesigneachproceduretobegeneralenoughtobeusedindifferentsituations.Functionallanguagestreatprocedureslikemathematicalfunctionsandallowthemtobeprocessedlikeanyotherdatainaprogram.Thisallowsamuchhigherandmorerigorouslevelofprogramconstruction.Functionallanguagesalsoallowvariables—symbolsfordatathatcanbespecifiedandchangedbytheuserastheprogramisrunning—tobegivenvaluesonlyonce.Thissimplifiesprogrammingbyreducingtheneedtobeconcernedwiththeexactorderofstatementexecution,sinceavariabledoesnothavetoberedeclared,orrestated,eachtimeitisusedinaprogramstatement.Manyoftheideasfromfunctionallanguageshavebecomekeypartsofmanymodernprocedurallanguages.Object-orientedlanguagesareoutgrowthsoffunctionallanguages.Anobjectorientedlanguageusesconceptsofclasses,objects,andmethods.Inobject-orientedlanguages,thecodeusedtowritetheprogramandthedataprocessedbytheprogramaregroupedtogetherintounitscalledobjects.Objectsarefurthergroupedintoclasses,whichdefinetheattributesobjectsmusthave.AsimpleexampleofaclassistheclassBook.ObjectswithinthisclassmightbeNovelandShortStory.Objectsalsohavecertainfunctionsassociatedwiththem,calledmethods.Thecomputeraccessesanobjectthroughtheuseofoneoftheobject’smethods.Themethodperformssomeactiontothedataintheobjectandreturnsthisvaluetothecomputer.Thepurposeofobjectorientationistomodel,incode,theobjectsthatmakeuptheapplicationyou’rewritingandtheinteractionsbetweenthem.Asinhumanlanguage,it’simpossibletodescribeanyprocesswithoutreferringtothenounsthatareinvolved.Allprogramminglanguagesprovidesomenouns,butuntilobject-orientedlanguagesarrivedonthescene,theprogrammercouldn’tcreatehis/herownnounsveryeasily.Programmingwaslimitedtotalkingaboutthesetofnounsprovidedbyalanguage:numbers,characters,channels,etc.Ofcourse,programmersbuiltmoreabstractstructuresaroundthislimitedsetofnouns,butthecodethatdescribedthoseabstractionswasmuchmorecomplexthantalkingabouttheminEnglish.Object-orientedlanguagesallowyoutodefinetypesofobjects(calledclasses)thatarederivedfrom,orcomposedof,othertypes.Inadditiontothisdatacomponent,thefunctions(alsocalledmethods)that“belong”tothedataarealsogroupedintheclass.Thishasatleastthreebenefits:Encapsulation.Functionsthatareinternaltoaclasscanbemarkedas“private”.Thismeansthatthey’rehiddenfromanycodeoutsidetheclass,sotheirimplementationcanbechangedwithoutbotheringanycodethatusestheclass.Conversely,themethodsthataremarked“public”formawell-definedinterfacethatshouldnotbechangedwithoutdueconsideration,becauseclientcodereliesonit.Inheritance.Youcanderiveoneclassfromanother,andthenewclassautomaticallycontainsallofthemethodsanddataoftheoriginalclass.Thisisusefulwhensomesubsetofyourobjectsneedsanadditionalcapability,butyoudon’twanttogivethatcapabilitytoalloftheotherobjects.Polymorphism.Pollywho?It’saGreek-derivedtermthatmeans“manyforms”.InOOP,itmeansthatsendingthesamemessage(inmostOOlanguages,thismeanscallingamethodbyname)mayevokedifferentresponsesdependingontype.Polymorphismitselfhasmorethanoneform.Thefirstformiswhenaderivedclassoverridesaninheritedmethodwithitsownimplementation,sothatsendingthesamemessage(callingthesamefunction)ontwodifferentobjectsyieldsadifferentbehaviordependingontheirtypes.Asecondtypeofpolymorphismiscalled“parametricpolymorphism”,whichmeansthataclassprovidesdifferentimplementationsforamethoddependingonthetypesofparameterspassedtoit.Logiclanguagesuselogicastheirmathematicalbase.Alogicprogramconsistsofsetsoffactsandif-thenrules,whichspecifyhowonesetoffactsmaybededucedfromothers,forexample:IfthestatementXistrue,thenthestatementYisfalse.Intheexecutionofsuch
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 讓課堂充滿生機(jī)與活力
- 2025年槍托項(xiàng)目可行性研究報(bào)告
- 2025年度航空航天裝備研發(fā)合作合同
- 信用社終止貸款合同范本
- 儲(chǔ)值合同范本
- 保時(shí)捷買賣合同范本
- 公司對個(gè)人轉(zhuǎn)讓合同范例
- 優(yōu)信網(wǎng)出租車合同范例
- 交通管制合同范本
- 企業(yè)公司聘用合同范本
- 高中物理《光電效應(yīng)》
- 烹飪實(shí)訓(xùn)室安全隱患分析報(bào)告
- 《金屬加工的基礎(chǔ)》課件
- 運(yùn)輸行業(yè)春節(jié)安全生產(chǎn)培訓(xùn) 文明駕駛保平安
- 體驗(yàn)式沙盤-收獲季節(jié)
- HGE系列電梯安裝調(diào)試手冊(ELS05系統(tǒng)SW00004269,A.4 )
- 找人辦事協(xié)議
- 老年護(hù)理陪護(hù)培訓(xùn)課件
- 醬香型白酒工廠設(shè)計(jì)
- 第3章 環(huán)境感知技術(shù)
- 牽引管道孔壁與管道外壁之間注漿技術(shù)方案
評論
0/150
提交評論