




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
外文资料C+isdesignedtobeanextensibleplatformforrapidlydevelopingprogramanalysistools.SeveralfeaturesofC+facilitatethis:Byconvention,C+writteninlowercaselettersrefersjusttotheprogramthatabstractsdatafromaC+program.CIA+writtenincapitallettersreferstothesystemmadeofthatabstractorandallofthetoolsthatusethedatabaseitgenerates.Entitiesincludeles,macros,types,functionsandvariables.SeparationofInformationExtractionandPresentation:Theprocessofextractinginformationfromaprogramandtheprocessofpresentingthatinformationshouldbeseparate.ThiseliminatestheneedforeachC+analysistooltoduplicatetheparsingprocessandallowsC+toolstosharetheinformationandpresentitindifferentways.AsimilardoctrinewasdevelopedintheInterlispproject.Unfortunately,manyCandC+toolstodaystillviolatethisbasicprinciple.ThesebasicdesignprinciplesgivetoolsbasedonC+anadvantageovermanytraditionaldevelopmenttools,whichusuallymergetheinformationextractionandpresentationprocessesinasingletoolanddonotsharetheinformationwithothertools.Thefirstprogramminglanguageswereverydependentontheunderlyingmachinearchitecture.Writingprogramsatthislevelofdetailisverycumbersome.Justashardwareengineerslearnedhowtobuildcomputersystemsoutofothercomponents,languagedesignersalsorealizedthatprogramscouldbewrittenatamuchhigherlevel,therebyshieldingtheprogrammerfromthedetailsoftheunderlyingmachine.SoftwareDesignthroughParadigmsWhendesigningsmallcomputerprogramsorlargesoftwaresystems,weoftenhaveamentalmodeloftheproblemwearetryingtosolve.Howdowedeviseamentalmodelofasoftwaresystem?Programmingparadigmsoffermanydifferentwaysofdesigningandthinkingaboutsoftwaresystems.Aparadigmcanbethoughtofasamentalmodelorasaframeworkfordesigninganddescribingasoftwaresystemsstructure.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,weoftenneedaparticulardatatypetouseinordertocarryoutthealgorithmsoperations.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.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.Recallthattheimportanceofdataabstractionistohidetheimplementationdetailsofadataobjectfromtheuser.TheuseronlyaccessestheobjectthroughitsPUBLICINTERFACE.AC+classconsistsofapublicandprivatepart.Thepublicpartprovidestheinterfacetotheusersoftheclass,whiletheprivatepartcanonlybeusedbythefunctionsthatmakeuptheclass.C+provideskeywordstoindicatewhichmembersofaclassarehiddenandwhicharepartofitspublicinterface.Themembersofthehiddenimplementationaremarkedinsectionsbeginningwiththekeywordprivate.Thepublicinterfacepartoftheclassfollowsthekeywordpublic.Bydefault,thedeclarationswithinaclassareprivate,meaningthatonlythememberfunctions(andfriends)oftheclasshaveaccesstothem.Aclassdefinitiondoesnotallocateanymemory.Memoryisallocatedwhenanarrayobjectiscreatedthroughavariabledeclaration.Constructorsanddestructorsprovidetheinitializationandcleanupofanobject.Whenanobjectisdeclared,theconstructoriscalledtoinitializethememoryusedbytheobject.Thedestructorperformsanyclean-upfortheobjectwhentheobjectgoesoutofscopeandisdestroyed.Notethatwedidntreallyhidetheimplementationdetailsfromtheuser.C+doesnotprovideawaytocompletelyexcludeallofthedetailsoftheunderlyingimplementation,sincetheprivatepartoftheclassmustbeincludedwiththeclassdefinitionitisusefultorelaxtheaccesstovariableswithinaclass,particularlyunderinheritance.Oftenderivedclassesneedeasyaccesstotheprivatemembersoftheirparentclasses.C+definesthekeywordprotectedforthispurpose.Protectedmemberscanbeaccessedbythememberfunctionsofaclassaswellasbymemberfunctionsofderivedclasses.However,likeprivatemembers,protectedmemberscannotbeaccessedbyuserprograms.Object-orientationhasbecomeabuzzwordwithmanymeanings.Itisadesignmethodology,aparadigm(awayofthinkingaboutproblemsandfindingsolutions),andaformofprogramming.Asadesignmethodology,wecanuseobject-orientedtechniquestodesignsoftwaresystems.Butitismorethanadesignmethodology,itisawholenewwayofthinkingaboutproblems.Object-orienteddesignallowsustothinkabouttheactualreal-worldentitiesoftheproblemweareattemptingtoprovideasolutionfor.Beginningthedesignwithconceptsfromthereal-worldproblemdomainallowsthesameconceptstobecarriedovertoimplementation,makingthedesignandimplementationcyclemoreseamless.Onceadesignhasbeenconceived,aprogramminglanguagecanbechosenforimplementation.Byfactoringouttheinheritancerelationshipsfromtheobjecthierarchiesdiscoveredduringdesign,onecanevenimplementthesysteminatraditional,non-object-orientedlanguage.However,usinganobject-orientedlanguage,suchasC+,makesiteasiertorealizethedesignintoanimplementationbecausetheinherentrelationshipsamongobjectscanbedirectlysupportedinthelanguage.LanguagessuchasC+areconsideredhybridlanguagesbecausetheyaremulti-paradigmlanguages.C+isanobject-orientedextensionofCandcanbeusedasaprocedurallanguageorasanobject-orientedlanguage.Inthisissue,wecontinueourtouroftheobject-orientedfeaturesofC+.Oneofthemajorstrengthsofanyobject-orientedprogramminglanguageistheabilitytobuildotherclassesfromexistingclasses,therebyreusingcode.Inheritanceallowsexistingtypestobeextendedtoanassociatedcollectionofsub-types.Recallthatoneofthekeyactionsofobject-orienteddesignistoidentifyreal-worldentitiesandtherelationshipsamongthem.Whenasoftwaresystemisdesigned,avarietyofobjectsarise,whichmayberelatedinonewayoranother.Someclassesmaynotberelatedatall.Manytimesitmakessensetoorganizetheobjectclassesintoaninheritancehierarchy.Organizingasetofclassesintoaclasshierarchyrequiresthatweunderstandtherelationshipsamongtheclassesindetail.Notallclassrelationshipsdictatethatinheritancebeused.C+providesthreeformsofinheritance:public,private,andprotected.Thesedifferentformsareusedfordifferentrelation-shipsbetweenobjects.Toillustratethesedifferenttypesofinheritance,letslookatseveraldifferentclassrelationships.Itisbesttousecompositionwherepossible.Incaseswhereyoumustoverridefunctionsinabaseclassthenbyallmeansuseinheritance.Onlyusepublicinheritanceifyourderivedclassisindeedaspecializationofthebaseclass,otherwise,privateinheritanceshouldbeused.Needlesslyusinginheritancemakesyoursystemhardertounderstand.Insummary,aclassspecifiestwointerfaces:onetotheusersoftheclass(thepublicinterface)andanothertoimplementersofderivedclasses(theunionofpublicandprotectedparts).Inheritanceworksalmostidentically.Whentheinheritanceispublic,thepublicinterfaceofthebaseclassbecomespartofthepublicinterfacetousersofthederivedclass.Whentheinheritanceisprotected,thepublicandprotectedpartsofthebaseclassareaccessibletothememberfunctions(theimplementation)ofthederivedclasses,butnottogeneralusersofthederivedclasses.Finally,wheninheritanceisprivate,thepublicandprotectedpartsofthebaseclassareonlyaccessibletotheimplementeroftheclass,butnottousersorderivedclasses.Polymorphismisthelastofthethreefundamentalprimitivesofobject-orientedprogrammingandthemostimportant.Togetherwithinheritance,polymorphismbringsthemostpower,intermsofrun-timeflexibility,toobject-orientedprogramming.Polymorphism,whichmeansmanyforms,providesagenericsoftwareinterfacesothatacollectionofdifferenttypesofobjectsmaybemanipulateduniformly.C+providesthreedifferenttypesofpolymorphism:virtualfunctions,functionnameoverloading,andoperatoroverloading.Thevirtualfunctionmechanismcanonlybeinvokedthroughtheuseofabaseclassreferenceorpointer.Recallthatabaseclasspointercanpointtoanobjectofthebasetypeoranobjectofanytypethatisderivedfromthebaseclass.Virtualfunctionsarealsousedtoimplementthelogicgatehierarchy.Theclassgateisanabstractbaseclassattherootoftheinheritancehierarchy.Aclassisconsideredabstractwhensomeofitsvirtualmemberfunctionsdonothaveanimplementation.Thesefunctionsareassignedtobezerointheclassdefinition.Derivedclassesmustprovideimplementationsforthem.AnotherformofpolymorphismfoundinC+isfunctionoverloading.Afunctionissaidtobeoverloadedwhenitisdeclaredmorethanonceinaprogram.Overloadingallowsasetoffunctionsthatperformasimilaroperationtobecollectedunderthesamename.Whenthereareseveraldeclarationsofthesamefunction,thecompilerdetermineswhichfunctionshouldbecalledbyexaminingthereturntypeandargumentsignatureofthefunctioncall.Whenwedefinenewdatatypes,itisoftenusefultodefinestandardoperationsthatarefoundinsimilartypes.Forexample,acomplextypealsohasadditionandsubtractiondefinedforit.Wecanuseoperatoroverloadingsothattheaddition(+)andsubtraction(-)operatorsworkforcomplexobjectsjustastheydoforintsandfloats.OperatorsaredefinedinmuchthesamewasasnormalC+functionsandcanbemembersornon-membersofaclass.Operatorstakeoneortwoargumentsandarecalledunaryandbinaryoperatorsaccordingly.InC+,amemberoperatorfunctionisdefinedlikeanordinarymemberfunction,butthenameisprefixedwiththekeywordoperator.中文翻译C+被设计成一个用于快速开发程序分析工具的可扩展平台。C+有以下几个特点:按照惯例,C+中小写字母是指书写的程序,只是从C+程序的摘要数据。C+中的大写字母书写,是指该摘要作者和使用的工具生成所有数据库中取得的。宏包括单位类型、函数和变量。这些基本的设计原理为基于C+中编程提供基础,在许多传统的开发工具中,通常的信息提取和合并是在一个单一的工具演示过程中的,不能共享与其他工具的信息优势。一种语言不仅要符合一种范例,而且能够使用多种范例提供的特性和特征。混合语言,如C+,综合了两到三种范例。C+包括了命令和程序范例的特性,例如,其前身C,和面向对象范例。当我们设计一个算法时,需要一个特定的数据类型执行算法的操作。如果可以定义变量的数据类型,而不影响到实际数据类型的运行,就可以很容易的制订出算法。通过定义数据的用法和操作,假定可以选择任何一种运行,这种定义就叫做抽象数据类型。抽象数据类型的使用使得算法的设计得到更大的推广,使得我们在算法设计时,注重了算法的全面,而不会拘泥于运行的细节。当算法设计完成时,实际的数据类型被执行。近来,程序语言扩展到支持新的数据类型的定义和提供便利给数据抽象。面向对象的范例:它仍然保留了许多程序范例的特征,过程仍然是计算的主要形式。但是,程序不仅仅是抽象值的运算,在面向对象范例种还有对对象的运算。对象同抽象数据类型很相似,联系着数据和运算。面向对象范例具有三种主要特性,第一种,压缩,其机制是为了实施数据抽象。第二种,继承。继承允许从已存在的对象中创建新的对象。这个新创建的对象是原对象的具体说明。新对象的不同在于只需要提供方法或数据。当一个对象从另一个对象中被创建或取得时,就说新对象继承了它父对象的方法和数据,并增加了一些新的描述和说明。面向对象的第三种特性是多态。多态可以使不同类型的的对象对相同的信息执行相同的操作。例如,我们有一部分对象它们可以执行一类操作,但是只有在运行时我们才知道对象的类型。面向对象语言包含的机制确保了每一类信息传递给正确的对象。构建一个面向对象的程序需要决定解决问题所需的对象。这些对象被用来构建计算,定义软件系统的操作运行。信息的传递是对象间最基本的相互作用机制。信息(从其他的对象或程序)传递给对象,以便通知对象运行下一个操作。对象需要负责维护它所相关的数据的状态。只有对象本身才可以改变它内部的数据值。对象本身可以完全的调用它的子对象。一个对象的执行是一个循环
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 企业投融资风险控制管理办法
- 2025年整形美容考试试题及答案
- 小学科学四年级分离食盐实验教学设计
- 税收筹划自考试题及答案
- 毕业生职业发展规划指导
- 小学四年级语文上册期末试题题库
- 园林绿化养护人员岗位技能培训
- 六年级数学试卷解析及阶段性辅导策略
- 小学英语课程教学设计方案
- 压力容器使用单位安全总监-特种设备考试题库及答案
- 人教版六年级上册道德与法治教案(5篇)
- 第1课 从食物采集到食物生产 课件-高二历史统编版(2019)选择性必修2 经济与社会生活
- 生涯拍卖会课件高一上学期主题班会
- 中医形神兼养
- GB/T 44241-2024虚拟电厂管理规范
- SYT 6680-2021 石油天然气钻采设备 钻机和修井机出厂验收规范-PDF解密
- 实用美术基础中职全套教学课件
- 子宫内膜癌的预防和早期发现
- 债权债务法律知识讲座
- 个人停车位租赁合同模板
- 食品保质期检测记录表
评论
0/150
提交评论