c++英语文献.docx
- 文档编号:5403554
- 上传时间:2022-12-16
- 格式:DOCX
- 页数:11
- 大小:26.81KB
c++英语文献.docx
《c++英语文献.docx》由会员分享,可在线阅读,更多相关《c++英语文献.docx(11页珍藏版)》请在冰豆网上搜索。
c++英语文献
Object-OrientationandC++
C++isjustoneofmanyprogramminglanguagesinusetoday.Whyaretheresomanylanguages?
Whydonewonesappeareveryfewyears?
Programminglanguageshaveevolvedtohelpprogrammerseasethetransitionfromdesigntoimplementation.
Thefirstprogramminglanguageswereverydependentontheunderlyingmachinearchitecture.Writingprogramsatthislevelofdetailisverycumbersome.Justashardwareengineerslearnedhowtobuildcomputersystemsoutofothercomponents,languagedesignersalsorealizedthatprogramscouldbewrittenatamuchhigherlevel,therebyshieldingtheprogrammerfromthedetailsoftheunderlyingmachine.
Whyaretheresuchalargenumberofhigh-levelprogramminglanguages?
Therearelanguagesforaccessinglargeinventorydatabases,formattingfinancialreports,controllingrobotsonthefactoryfloor,processinglists,controllingsatellitesinrealtime,simulatinganuclearreactor,predictingchangingatmosphericconditions,playingchess,anddrawingcircuitboards.Eachoftheseproblemsrequiresdifferentsetsofdatastructuresandalgorithms.Programminglanguagesaretoolstohelpussolveproblems.However,thereisnotoneprogramminglanguagethatisbestforeverytypeofproblem.Newprogramminglanguagesareoftendevelopedtoprovidebettertoolsforsolvingaparticularclassofproblems.Otherlanguagesareintendedtobeusefulforavarietyofproblemdomainsandaremoregeneralpurpose.
Eachprogramminglanguageimpartsaparticularprogrammingstyleordesignphilosophyonitsprogrammers.Withthemultitudeofprogramminglanguagesavailabletoday,anumberofsuchdesignphilosophieshaveemerged.Thesedesignphilosophies,calledprogrammingparadigms,helpustothinkaboutproblemsandformulatesolutions.
SoftwareDesignthroughParadigms
Whendesigningsmallcomputerprogramsorlargesoftwaresystems,weoftenhaveamentalmodeloftheproblemwearetryingtosolve.Howdowedeviseamentalmodelofasoftwaresystem?
Programmingparadigmsoffermanydifferentwaysofdesigningandthinkingaboutsoftwaresystems.Aparadigmcanbethoughtofasamentalmodelorasaframeworkfordesigninganddescribingasoftwaresystem'sstructure.Themodelhelpsusthinkaboutandformulatesolutions.
Wecanusethementalmodelofaparadigmindependentlyfromtheprogramminglanguagechosenforimplementation.However,whenthechosenlanguageprovidesconstructsandmechanismsthataresimilartothosethatarefoundintheparadigm,theimplementationwillbemorestraightforward.Usually,thereareseverallanguagesthatbelongtoaparadigm.Forthisreason,aprogrammingparadigmisalsoconsideredaclassoflanguages.
Alanguagedoesnothavetofitintojustoneparadigm.Moreoften,languagesprovidefeaturesorcharacteristicsfromseveralparadigms.Hybridlanguages,suchasC++,combinecharacteristicsfromtwoormoreparadigms.C++includescharacteristicsfromtheimperativeandproceduralparadigms--justlikeitspredecessorlanguage,C--andtheobject-orientedparadigm.
Theimperativeparadigmischaracterizedbyanabstractmodelofacomputerwithalargememorystore.ThisistheclassicvonNeumannmodelofcomputerarchitecture.Computations,whichconsistofasequenceofcommands,arestoredasencodingwithinthestore.Commandsenablethemachinetofindsolutionsusingassignmenttomodifythestore,variablestoreadthestore,arithmeticandlogictoevaluateexpressions,andconditionalbranchingtocontroltheflowofexecution.
Theproceduralparadigmincludestheimperativeparadigm,butextendsitwithanabstractionmechanismforgeneralizingcommandsandexpressionsintoprocedures.Parameters,whichareessentiallyaliasesforaportionofthestore,werealsointroducedbythisparadigm.Otherfeaturesincludeiteration,recursion,andselection.Mostmainstreamsprogrammingtodayisdoneinaprocedurallanguage.
Theproceduralparadigmwasthefirstparadigmtointroducethenotionofabstractionintoprogramdesign.Thepurposeofabstractioninprogrammingistoseparatebehaviorfromimplementation.Proceduresareaformofabstraction.Theprocedureperformssometaskorfunction.Otherpartsoftheprogramcalltheprocedure,knowingthatitwillperformthetaskcorrectlyandefficiently,butwithoutknowingexactlyhowtheprocedureisimplemented.
DATAABSTRACTIONisconcernedwithseparatingthebehaviorofadataobjectfromitsrepresentationorimplementation.Forexample,astackcontainstheoperationsPush,Pop,andIsEmpty.Astackobjectprovidesuserswiththeseoperations,butdoesnotrevealhowthestackisactuallyimplemented.Thestackcouldbeimplementedusinganarrayoralist.Usersofthestackobjectdonotcarehowthestackisimplemented,onlythatitperformstheaboveoperationscorrectlyandefficiently.Becausetheunderlyingimplementationofthedataobjectishiddenfromitsusers,theimplementationcaneasilybechangedwithoutaffectingtheprogramsthatuseit.
Whenwedesignalgorithms,weoftenneedaparticulardatatypetouseinordertocarryoutthealgorithm'soperations.Thedesignofanalgorithmiseasierifwesimplyspecifythedatatypesofthevariables,withoutworryingabouthowtheactualdatatypeisimplemented.Wedescribethedatatypebyitspropertiesandoperationsandassumethatwhateverimplementationischosen,theoperationswillworkcorrectlyandefficiently.TypesdefinedinthiswayarecalledABSTRACTDATATYPES(ADTs).
Theuseofabstractdatatypesmakesthedesignofthealgorithmmoregeneral,andallowsustoconcentrateonthealgorithmathandwithoutgettingboggeddowninimplementationdetails.Afterthealgorithmshavebeendesigned,theactualdatatypeswillneedtobeimplemented,alongwiththealgorithms.Recently,procedurallanguageshavebeenextendedtosupportthedefinitionofnewdatatypesandprovidefacilitiesfordataabstraction.
Theobject-orientedparadigmretainsmuchofthecharacteristicsoftheproceduralparadigm,sinceproceduresarestilltheprimaryformforcomposingcomputations.However,ratherthanoperateonabstractvalues,programsintheobject-orientedparadigmoperateonobjects.Anobjectisverysimilartoanabstractdatatypeandcontainsdataaswellasprocedures.
Therearethreeprimarycharacteristicsoftheobject-orientedparadigm.Wehavealreadydescribedthefirst,ENCAPSULATION,themechanismforenforcingdataabstraction.ThesecondcharacteristicisINHERITANCE.Inheritanceallowsnewobjectstobecreatedfromexisting,moregeneralones.Thenewobjectbecomesaspecializedversionofthegeneralobject.Newobjectsneedonlyprovidethemethodsordatathatdifferbecauseofthespecialization.Whenanobjectiscreated(orderived)fromanotherobject,itissaidtoinheritthemethodsanddataoftheparentobject,andincludesanynewrepresentationsandneworrevisedmethodsaddedtoit.
Thethirdandfinalcharacteristicofobject-orientedprogrammingisPOLYMORPHISM.Polymorphismallowsmanydifferenttypesofobjectstoperformthesameoperationbyrespondingtothesamemessage.Forexample,wemayhaveacollectionofobjectswhichcanallperformasortoperation.However,wedonotknowwhattypesofobjectswillbecreateduntilrun-time.Object-orientedlanguagescontainmechanismsforensuringthateachsortmessageissenttotherightobject.
Encapsulation,inheritance,andpolymorphismareconsideredthefundamentalcharacteristicsofobject-orientedprogrammingandallobject-orientedlanguagesmustprovidethesecharacteristicsinsomeway.Notsurprisingly,languagessupportthesecharacteristicsinverydifferentways.Smalltalk,C++,Objective-C,andLispwithCLOS(theCommonLispObjectSystem)areallexamplesofobject-orientedlanguages,andeachprovidessupportforencapsulation,inheritance,andpolymorphism.
Constructinganobject-orientedprograminvolvesdeterminingtheobjectsthatareneededtosolvetheproblem.Theobjectsarethenusedtoconstructcomputationsthatdefinethebehaviorofthesoftwaresystem.Messagepassingisthefundamentalinteractionmechanismamongobjects.Messages(fromotherobjectsorprograms)aresenttoobjectstoinformthemtoperformoneoftheiroperations.
Objectsareresponsibleformaintainingthestateoftheirdata.Onlytheobjectmaymodifyitsinternaldata.Objectsmaythemselvesbeimplementedviaothersub-objects.Implementinganobjectinvolvesarecursiveprocessofbreakingitintosub-objectsuntilatsomeleveltheobjectsandmethodsdefinedonthemareprimitives.Atthispoint,themethodsanddataconsistofelementsthatcanbeimplementedusingthebasicconstructsprovidedbytheprogramminglanguage.
Oneofthemostimportantaspectsoftheobject-orientedparadigmishowitchangesourwayofthinkingaboutsoftwaresystems.Systemsarethoughtofasconsistingofindividualentitiesthatareresponsibleforcarryingouttheirownoperations.Eachobjectisconceivedandimplementedasself-contained.Suchamodelfacilitatessoftwaredesign(andlaterimplementation)becauseobjectsoftenmodelconceptualreal-worldentities.Designingsystemsusingtheobject-orientedparadigmresultsinsoftwaresystemsthatbehaveandappearmoreliketheirreal-lifecounterparts.
TheObject-OrientedCharacteristicsofC++
C++extendsCwithafacilityfordefiningnewdatatypes.AclassislikeaCstruct,butcontainsdataaswellasmethods.Inaddition,C++providesdifferentlevelsofaccesstothemembersofaclassinordertocontrolhowthemembersofaclasscanbemanipulatedfromoutsidetheclass.
Recallthattheimportanceofdataabstractionistohidetheimplementationdetails
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c+ 英语 文献
![提示](https://static.bdocx.com/images/bang_tan.gif)