首页 API Design for C++.pdf

API Design for C++.pdf

API Design for C++.pdf

上传者: tangwei19811102 2013-09-16 评分1 评论0 下载30 收藏0 阅读量1006 暂无简介 简介 举报

简介:本文档为《API Design for C++pdf》,可适用于专题技术领域,主题内容包含APIDesignforCAPIDesignforCMartinReddyAMSTERDAM•BOSTON•HEIDELBERG•LONDONNEW符等。

APIDesignforCAPIDesignforCMartinReddyAMSTERDAM•BOSTON•HEIDELBERG•LONDONNEWYORK•OXFORD•PARIS•SANDIEGOSANFRANCISCO•SINGAPORE•SYDNEY•TOKYOMorganKaufmannPublishersisanimprintofElsevierAcquiringEditor:ToddGreenNopartofthispublicationmaybereproducedortransmittedinanyformorbyanymeans,electronicormechanical,includingphotocopying,recording,oranyinformationstorageandretrievalsystem,withoutpermissioninwritingfromthepublisherDetailsonhowtoseekpermission,furtherinformationaboutthePublisher’spermissionspoliciesandourarrangementswithorganizationssuchastheCopyrightClearanceCenterandtheCopyrightLicensingAgency,canbefoundatourwebsite:wwwelseviercompermissionsThisbookandtheindividualcontributionscontainedinitareprotectedundercopyrightbythePublisher(otherthanasmaybenotedherein)NoticesKnowledgeandbestpracticeinthisfieldareconstantlychangingAsnewresearchandexperiencebroadenourunderstanding,changesinresearchmethodsorprofessionalpracticesmaybecomenecessaryPractitionersandresearchersmustalwaysrelyontheirownexperienceandknowledgeinevaluatingandusinganyinformationormethodsdescribedhereinInusingsuchinformationormethodstheyshouldbemindfuloftheirownsafetyandthesafetyofothers,includingpartiesforwhomtheyhaveaprofessionalresponsibilityTothefullestextentofthelaw,neitherthePublishernortheauthors,contributors,oreditors,assumeanyliabilityforanyinjuryandordamagetopersonsorpropertyasamatterofproductsliability,negligenceorotherwise,orfromanyuseoroperationofanymethods,products,instructions,orideascontainedinthematerialhereinLibraryofCongressCataloginginPublicationDataApplicationsubmittedBritishLibraryCataloguinginPublicationDataAcataloguerecordforthisbookisavailablefromtheBritishLibraryISBN:PrintedintheUnitedStatesofAmericaEditorialAssistant:RobynDayProjectManager:AndreCuelloDesigner:EricDeCiccoMorganKaufmannisanimprintofElsevierCorporateDrive,Suite,Burlington,MA,USA#Elsevier,IncAllrightsreservedForinformationonallMKpublicationsvisitourwebsiteatwwwmkpcomForewordIshouldbeginbyconfessingthatIdonotconsidermyselfaworldclassAPIdesignerorsoftwareengineerIdo,however,considermyselfanexpertresearcherintheareasofcomputergraphicsandgeometricmodelingItwasinthislineofworkthatIfirstmetMartinatPixarAnimationStudiosxvAsagraphicsresearcherIwasaccustomedtowritingmathematicallysophisticatedpapersIwasalsoformallytrainedasacomputerscientistatamajoruniversityandhadwrittenmyshareofcodeArmedwiththisbackground,whenIwaspresentedwiththeopportunitytoleadagroupofsoftwareengineersworkingonanewgenerationofanimationsoftwareforPixar,Ifiguredthatitcouldn’tbeanymoredifficultthanresearchAfterall,researchis,bydefinition,thecreationoftheunknown,whereasengineeringistheimplementationofwellunderstoodsubjectsIcouldnothavebeenmorewrongIcametorealizethatsoftwareengineeringwas,withoutadoubt,themostdifficultchallengeIhadeverbeenpresentedwithAftermoreyearsthanIcaretoadmit,IeventuallygaveupandwentbacktographicsresearchIcan’ttellyouhowmuchIwouldhavebenefittedfromabooksuchas“APIDesignforC”ManyofthelessonswelearnedthehardwayhavebeencapturedbyMartininthisinsightful,easytousebookMartinapproachesthesubjectnotfromtheperspectiveofanacademicsoftwareresearcher(althoughhedrawsheavilyfromresultsandinsightsgainedthere),butfromtheperspectiveofaninthetrenchessoftwareengineerandmanagerHehasexperiencedfirsthandtheimportanceofgoodsoftwaredesignandhasemergedasanarticulatevoiceofwhat“good”meansInthisbookhepresentseffectivestrategiesforachievingthatgoalIparticularlylikethatMartinisnotfocusingjustonAPIdesign,butmorebroadlyonsoftwarelifecycles,allowinghimtocovertopicssuchasversioning,strategiesforbackwardcompatibility,andbranchingmethodologiesInshort,thisbookshouldbeofgreatvaluetothosecreatingormanagingsoftwareactivitiesItisacomprehensivecollectionofbestpracticesthathaveproventhemselvestimeandtimeagainTonyDeRoseSeniorScientistandResearchGroupLead,PixarAnimationStudiosAnAPIpresentsalogicalinterfacetoasoftwarecomponentandhidestheinternaldetailsrequiredtoimplementthatcomponentItoffersahighlevelabstractionforamoduleandpromotesmorecostlytofixthanabuginyourimplementationForinstance,aninterfacechangemayrequirealloftheapplicationsbasedonyourcodetobeupdated,whereasanimplementacanbeintegratedtransparentlyandeffortlesslyintoclientapplicationswhenthetiononlychangeyadoptthenewxviicodereusebyallowingmultipleapplicationstosharethesamefunctionalityModernsoftwaredevelopmenthasbecomehighlydependentonAPIs,fromlowlevelapplicationframeworkstodataformatAPIsandgraphicaluserinterface(GUI)frameworksInfact,commonsoftwareengineeringtermssuchasmodulardevelopment,codereuse,componentization,dynamiclinklibraryorDLL,softwareframeworks,distributedcomputing,andserviceorientedarchitectureallimplytheneedforstrongAPIdesignskillsSomepopularCandCAPIsthatyoumayalreadybeawareofincludetheStandardTemplateLibrary(STL),Boost,theMicrosoftWindowsAPI(Win),MicrosoftFoundationClasses(MFC),libtiff,libpng,zlib,libxml,OpenGL,MySQL,Trolltech’sQt,wxWidgets,GTK,KDE,SkypeKit,POSIXpthreads,Intel’sThreadingBuildingBlocks,theNetscapePluginAPI,andtheApachemoduleAPIInaddition,manyofGoogle’sopensourceprojectsareC,asismuchofthecodeonthesourceforgenet,bitbucketorg,andfreshmeatnetWebsitesAPIssuchastheseareusedinallfacetsofsoftwaredevelopment,fromdesktopapplications,tomobilecomputingandembeddedsystems,toWebdevelopmentForexample,theMozillaFirefoxWebbrowserisbuiltontopofmorethandynamiclibraries,eachofwhichprovidestheimplementationforoneormoreAPIsElegantandrobustAPIdesignisthereforeacriticalaspectofcontemporarysoftwaredevelopmentOneimportantwayinwhichthisdiffersfromstandardapplicationdevelopmentisthefargreaterneedforchangemanagementAsweallknow,changeisaninevitablefactorinsoftwaredevelopmentnewrequirements,featurerequests,andbugfixescausesoftwaretoevolveinwaysthatwereneveranticipatedwhenitwasfirstdevisedHowever,changestoanAPIthatissharedbyhundredsofenduserapplicationscancausemajorupheavalandultimatelymaycauseclientstoabandonanAPITheprimarygoalofgoodAPIdesignisthereforetoprovideyourclientswiththefunctionalitytheyneedwhilealsocausingminimalimpacttotheircodeideallyzeroimpactwhenyoureleaseanewversionWHYYOUSHOULDREADTHISBOOKIfyouwriteCcodethatanotherengineerreliesupon,you’reanAPIdesignerandthisbookhasbeenwrittenforyouInterfacesarethemostimportantcodethatyouwritebecauseaproblemwithyourinterfaceisfarPrefaceWritinglargeapplicationsinCisacomplexandtrickybusinessHowever,designingreusableCinterfacesthatarerobust,stable,easytouse,anddurableisevenmoredifficultThebestwaytosucceedinthisendeavoristoadheretothetenetsofgoodApplicationProgrammingInterface(API)designimplementation,testing,documentation,release,versioning,maintenance,anddeprecationIwillxviiiPrefaceevencoverspecializedAPItopicssuchascreatingscriptingandpluginAPIsWhilemanyofthesetopicsarealsorelevanttosoftwaredevelopmentingeneral,thefocusherewillbeontheparticularimplicationsforAPIdesignForexample,whendiscussingtestingstrategiesIwillconcentrateonautomatedAPItestingtechniquesratherthanattemptingtoincludeenduserapplicationtestingtechniquessuchasGUItesting,systemtesting,ormanualtestingIntermsofmyowncredentialstowritethisbook,IhaveledthedevelopmentofAPIsforresearchcodesharedbyseveralcollaboratinginstitutions,inhouseanimationsystemAPIsthathavebeenusedtomakeAcademyAwardwinningmovies,andopensourceclientserverAPIsthathavebeenusedbymillionsofpeopleworldwideThroughoutallofthesedisparateexperiences,IhaveconsistentlywitnessedtheneedforhighqualityAPIdesignThisbookthereforepresentsapracticaldistillationofthetechniquesandstrategiesofindustrialstrengthAPIdesignthathavebeendrawnfromarangeofrealworldexperiencesWHOISTHETARGETAUDIENCEWhilethisbookisnotabeginner’sguidetoC,IhavemadeeveryefforttomakethetexteasytoreadandtoexplainallterminologyandjargonclearlyThebookshouldthereforebevaluabletonewprogrammerswhohavegraspedthefundamentalsofCandwanttoadvancetheirdesignskills,aswellasseniorengineersandsoftwarearchitectswhoareseekingtogainnewexpertisetocomplementtheirexistingtalentsTherearethreespecificgroupsofreadersthatIhaveborneinmindwhilewritingthisbookPracticingsoftwareengineersandarchitectsJuniorandseniordeveloperswhoareworkingonaspecificAPIprojectandneedpragmaticadviceonhowtoproducethemostelegantandenduringdesignTechnicalmanagersProgramandproductmanagerswhoareresponsibleforproducinganAPIproductandwhowanttogaingreaterinsightintothetechnicalissuesanddevelopmentprocessesofAPIdesignAPIversionPutinmoreeconomicterms,apoorlydesignedinterfacecanseriouslyreducethelongtermsurvivalofyourcodeLearninghowtocreatehighqualityinterfacesisthereforeanessentialengineeringskill,andthecentralfocusofthisbookAsMichiHenningnoted,APIdesignismoreimportanttodaythanitwasyearsagoThisisbecausemanymoreAPIshavebeendesignedinrecentyearsThesealsoprovidericherandmorecomplexfunctionalityandaresharedbymoreenduserapplications(Henning,)Despitethisfact,nootherbookscurrentlyonthemarketconcentrateonthetopicofAPIdesignforCIt’sworthnotingthatthisbookisnotmeanttobeageneralCprogrammingguidetherearealreadymanygoodexamplesoftheseonthemarketIwillcertainlycoverlotsofobjectorienteddesignmaterialandpresentmanyhandyCtipsandtricksHowever,IwillfocusontechniquesforrepresentingcleanmodularinterfacesinCBycorollary,Iwillnotdiveasdeeplyintothequestionofhowtoimplementthecodebehindtheseinterfaces,suchasspecificalgorithmchoicesorbestpracticeslimitedtothecodewithinthecurlybracesofyourfunctionbodiesHowever,thisbookwillcoverthefullbreadthofAPIdevelopment,frominitialdesignthroughxixPrefaceCONVENTIONSWhileitismoretraditionaltoemploytheterm“user”tomeanapersonwhousesasoftwareapplication,suchasauserofMicrosoftWordorMozillaFirefox,inthecontextofAPIdesignIwillapplythetermtomeanasoftwaredeveloperwhoiscreatinganapplicationandisusinganAPItoachieveFOCUSINGONCWhiletherearemanygenericAPIdesignmethodologiesthatcanbetaughtskillsthatapplyequallywelltoanyprogramminglanguageorenvironmentultimatelyanAPIhastobeexpressedinaparticularprogramminglanguageItisthereforeimportanttounderstandthelanguagespecificfeaturesthatcontributetoexemplaryAPIdesignThisbookisthereforefocusedontheissuesofdesigningAPIsforasinglelanguage(C)ratherthandilutingthecontenttomakeitapplicableforalllanguagesWhilereaderswhowishtodevelopAPIsforotherlanguages,suchasJavaorC#,maystillgainmuchgeneralinsightfromthistext,thebookisdirectlytargetedatCengineerswhomustwriteandmaintainAPIsforotherengineerstoconsumeCisstilloneofthemostwidelyusedprogramminglanguagesforlargesoftwareprojectsandtendstobethemostpopularchoiceforperformancecriticalcodeAsaresult,therearemanydiverseCandCAPIsavailableforyoutouseinyourownapplications(someofwhichIlistedearlier)IwillthereforeconcentrateonaspectsofproducinggoodAPIsinCandincludecopioussourcecodeexamplestoillustratetheseconceptsbetterThismeansthatIwilldealwithCspecifictopicssuchastemplates,encapsulation,inheritance,namespaces,operators,constcorrectness,memorymanagement,useofSTL,thepimplidiom,andsoonAdditionally,thisbookwillbepublishedduringanexcitingtimeintheevolutionofCAnewversionoftheCspecificationiscurrentlyworkingitswaythroughtheISOIECstandardizationprocessMostCcompilerscurrentlyaimtoconformtothestandardthatwasfirstpublishedin,knownasCAlaterrevisionofthisstandardwaspublishedintocorrectseveraldefectsSincethattime,thestandardscommitteehasbeenworkingonamajornewversionofthespecificationThisversionisreferredtoinformallyasCx,untilsuchtimethatthestandardisratifiedandthedateofpublicationisknownBythetimeyoureadthisbook,thenewstandardwilllikelyhavebeenpublishedHowever,atthetimeofwriting,itisstillreferredtoasCxNonetheless,Cxhasreachedanadvancedstageofthestandardizationprocess,andmanyofthenewfeaturescanbepredictedwithrelativelyhighconfidenceInfact,someofthemajorCcompilershavealreadystartedtoimplementmanyoftheproposednewfeaturesIntermsofAPIdesign,severalofthesenewlanguagefeaturescanbeusedtoproducemoreelegantandsturdyinterfacesAssuch,IhaveendeavoredtohighlightandexplainthoseareasofCxthroughoutthebookThisbookshouldthereforeremainarelevantresourceforseveralyearstocomeStudentsandeducatorsComputerscienceandsoftwareengineeringstudentswhoarelearninghowtoprogramandareseekingathoroughresourceonsoftwaredesignthatisinformedbypracticalexperienceonlargescaleprojectsxxPrefacethisInotherwords,IwillgenerallybetalkingaboutAPIusersandnotapplicationusersTheterm“client”willbeusedsynonymouslyinthisregardNotethattheterm“client,”inadditiontoreferringtoahumanuserofyourAPI,canalsoreferimpersonallytootherpiecesofsoftwarethatmustcallfunctionsinyourAPIWhiletherearemanyfileformatextensionsusedtoidentifyCsourceandheaderfiles,suchascpp,cc,cxx,h,hh,andhpp,Iwillstandardizeontheuseofcppandhthroughoutthisbook“Iwillalsousethetermsmoduleandcomponent”interchangeablytomeanasinglecppandhfilepairThesearenotablynotequivalenttoaclassbecauseacomponentormodulemaycontainmultipleclassesIwillusethetermlibrarytorefertoaphysicalcollection,orpackage,ofcomponents,thatis,library>modulecomponent>classThetermmethod,whilegenerallyunderstoodintheobjectorientedprogrammingcommunity,isnotstrictlyaCtermitoriginallyevolvedfromtheSmalltalklanguageTheequivalentCtermismemberfunction,althoughsomeengineerspreferthemorespecificdefinitionofvirtualmemberfunctionBecauseIamnotparticularlyconcernedwiththesubtletiesofthesetermsinthisbook,IwillusemethodandmemberfunctioninterchangeablySimilarly,althoughthetermdatamemberisthemorecorrectCexpression,IwilltreatthetermmembervariableasasynonymIntermsoftypographicalconventions,Iwilluseafixedwidthfonttotypesetallsourcecodeexamples,aswellasanyfilenamesorlanguagekeywordsthatmayappearinthetextAlso,IwillpreferuppercamelcaseforallclassandfunctionnamesintheexamplesthatIpresent,thatis,CamelCaseinsteadofcamelCaseorsnakecase,althoughobviouslyIwillpreservethecaseforanyexternalcodethatIreference,suchasstd::foreach()Ifollowtheconventionofusingan“m”prefixinfrontofdatamembers,forexample,mMemberVar,and“s”infrontofstaticvariables,forexample,sStaticVarItshouldbepointedoutthatthesourceexampleswithinthebookareoftenonlycodesnippetsandarenotmeanttoshowfullyfunctionalsamplesIwillalsooftenstripcommentsfromtheexamplecodeinthebookThisisdoneforreasonsofbrevityandclarityInparticular,IwilloftenomitanypreprocessorguardstatementsaroundaheaderfileIwillassumethatthereaderisawarethateveryCCheadershouldencloseallofitscontentwithinguardstatementsandthatit’sgoodpracticetocontainallofyourAPIdeclarationswithinaconsistentnamespace(ascoveredinChaptersand)Inotherwords,itshouldbeassumedthateachheaderfilethatIpresentisimplicitlysurroundedbycode,suchasthefollowing#ifndefMYMODULEH#defineMYMODULEHrequired#includefilesnamespaceapibook{APIdeclarations}#endifTIPIwillalsohighlightvariousAPIdesigntipsandkeyconceptsthroughoutthebookThesecalloutsareprovidedtoletyousearchquicklyforaconceptyouwishtorereadIfyouareparticularlypressedfortime,youcouldsimplyscanthebookforthesetipsandthenreadthesurroundingtexttogaingreaterinsightforthosetopicsthatinterestyouthemostBOOKWEBSITEThisbookalsohasasupportingWebsite,http:APIBookcomOnthissiteyoucanfindgeneralinformationaboutthebook,aswellassupportingmaterial,suchasthecompletesetofsourcecodeexamplescontainedwithinthetextFeelfreetodownloadandplaywiththesesamplesyourselftheyweredesignedtobeassimpleaspossible,whilestillbeingusefulandillustrativeIhaveusedthecrossplatformCMakebuildsystemtofacilitatecompilingandlinkingtheexamplessotheyshouldworkonWindows,MacOSX,andUNIXoperatingsystemsIwillalsopublishanyinformationaboutnewrevisionsofthisbookandanyerrataonthisWebsite,aswellasusefullinkstootherrelatedAPIresourcesontheInternet,suchasinterestingtoolkits,xxiPrefacearticles,andutilitiesThebookWebsitealsoprovidesaccesstoautilitythatIwrotecalledAPIDiffThisprogramletsyoucomparetwoversionsofanAPIandreviewdifferencestocodeorcommentsinavisualsidebysideformatYoucanalsogenerateareportofeverythingthatchangedinaparticularreleasesothatyourclientsknowexactlywhattolookoutforThisutilityisavailableforWindows,MacOSX,andLinuxportedmethroughoutthewholeprocess,whilealsoknowingexactlywhentomakemepauseandtakeabreakThankyouGenevieveforyourconstantloveandsupportxxiiiAcknowledgmentsThisbookhasbenefitedgreatlyfromthetechnicalreviewandfeedbackofseveralofmyesteemedcolleaguesIamindebtedtothemfortakingthetimetoreadearlyversionsofthemanuscriptandprovidethoughtfulsuggestionsforimprovementInparticular,IthankPaulStrauss,EricGregory,RychardeHawkes,NickLong,JamesChalfant,BrettLevin,MarcusMarr,JimHumelsine,andGeo

职业精品

XX有限公司(薪资福利管理制度).doc

公司采购流程管理制度制定方法.doc

招聘管理与面试技巧.ppt

公司采购流程管理制度.doc

用户评论

0/200
    暂无评论
上传我的资料

精彩专题

相关资料换一换

资料评价:

/ 446
所需积分:1 立即下载

意见
反馈

返回
顶部