c++英语文献.docx

上传人:b****4 文档编号:5403554 上传时间:2022-12-16 格式:DOCX 页数:11 大小:26.81KB
下载 相关 举报
c++英语文献.docx_第1页
第1页 / 共11页
c++英语文献.docx_第2页
第2页 / 共11页
c++英语文献.docx_第3页
第3页 / 共11页
c++英语文献.docx_第4页
第4页 / 共11页
c++英语文献.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

c++英语文献.docx

《c++英语文献.docx》由会员分享,可在线阅读,更多相关《c++英语文献.docx(11页珍藏版)》请在冰豆网上搜索。

c++英语文献.docx

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1