what is the difference between pool and prototype patterns?

文章推薦指數: 80 %
投票人數:10人

I've just read the chapter on Creational patterns in the book Design Patterns in golang. These are: factory; abstract factory; prototype ... Home Public Questions Tags Users Collectives ExploreCollectives FindaJob Jobs Companies Teams StackOverflowforTeams –Collaborateandshareknowledgewithaprivategroup. CreateafreeTeam WhatisTeams? Teams CreatefreeTeam CollectivesonStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore whatisthedifferencebetweenpoolandprototypepatterns? AskQuestion Asked 4years,3monthsago Active 3years,6monthsago Viewed 889times 2 2 I'vejustreadthechapteronCreationalpatternsinthebookDesignPatternsingolang.Theseare: factory abstractfactory prototype singleton builder I'vecreatedarepositoryongithubtolistallofthem.I'velookedforotherrepositorieslikemine: tmrts/go-patterns yksz/go-design-patterns jeanphorn/go-design-patterns Somelistobject-poolasapattern,otherssimple-factoryandfactory-method.Doesthereexistanofficiallistofcreationalpatternsingo?Isitimportanttoknowthelist,orisitmoreimportanttoknowwhatispossibleandbeabletouserightcodeinrightcontext?Withorwithoutknowallthepatternsintheworld? And,...whatisthedifferencebetweenprototypeandobjectpoolpatterns?Theylookverysimilartome. godesign-patterns Share Improvethisquestion Follow editedSep13'17at7:46 Flimzy 65.2k1515goldbadges111111silverbadges155155bronzebadges askedSep13'17at6:00 sensorariosensorario 17.2k2525goldbadges8787silverbadges141141bronzebadges 2 Hopefullyimprovedthequestionsufficienttoremainopen,@sensorariocanyouverifytoensureI'venotchangedanythingimportant. – MartinSpamer Sep13'17at7:04 Thereisnosuchthingas"anofficiallistofcreationalpatternsingo".There'snothingofficialaboutdesignpatterns;they'rejustthingsthatpeoplehavefoundtheyuseoftenenoughtogivethemnames. – Adrian Sep13'17at14:22 Addacomment  |  2Answers 2 Active Oldest Votes 6 APoolhelpslimitthenumberofnewobjectsallocated;aPrototypeisawayofspecifyinghowanewobjectiscreated. Objectpoolsareconcernedwithcachingcreatedinstancesofobjectsthatcanbeaccessedlater.Golanghasanimplementation(https://golang.org/pkg/sync/#Pool)whichismainlyusedforrelievingpressureonthegarbagecollector.Theusualwayofusingapoolfollowssomethinglike: askthepoolforaninstance Thepoolwilleithergiveyoubackanunusedobject,oritwillallocateanewobject,andgivethenewinstancebacktoyou Youusetheobjecttodowhateveryouneed Yougivetheobjectbacktothepoolsothatanother"client"canuseit. InthePoolimplementation,you'llnoticethatyoucanpassa"creation"functiontospecifyhowthepoolshouldcreateaninstanceinStep2. Newfunc()interface{} Thisfunctioncouldsimplyallocateanemptystruct,oritcoulduseaPrototypepatterntoclonenewinstancesifthecreationlogicwascomplicated. ThePrototypepatternismorefocusedonabstractinghowyoucancreatemany"copies"ofanobjectfromaprototypeobject.Youmainlyusethispatternwhenyouwanttotryandavoidtheuseofthenewkeyword. Share Improvethisanswer Follow answeredSep13'17at6:59 RyanDRyanD 24311silverbadge77bronzebadges 0 Addacomment  |  4 DesignPatternsdonotexistinisolation,theyhaverelationshipsoftheirown.Soforexample,anobjectpoolmightuseafactoryorprototypetoinitiallyfillthepoolordealwithexhaustion.Theobjectsinthatpoolmightconformtothecommandpattern,orbeexamplesofthebuilderpattern. Inpracticeyoucannotpossiblyknowallthedetailsofallpatterns,themostimportantthingtoknowistheintent.Whatthepatternachieves.Whenusingthepatterntheremainingdetailscanandshouldbetakenfromapatterncatalogue,overtimeyouwilllearnsomepatternscomprehensivelyandreferenceothers. APatternCatalogueistheacollectionoffullydocumentedDesignPatterns.TheGoFDesignPatternsbookisprobablythemostfamousPatternCatalogue,howeverthebookyoumentionandevengithubrepositoriescanfulfilthesamepurpose. Share Improvethisanswer Follow editedJun14'18at20:14 answeredSep13'17at6:44 MartinSpamerMartinSpamer 5,2972727silverbadges4444bronzebadges 1 1 Thankyouforyourresponse.IRyadresponsebutbecausemorefocusedonmyquestion.Alsoyourresponsewasusefulforme.Thankyouverymuch. – sensorario Sep13'17at7:24 Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedgodesign-patternsoraskyourownquestion. GoLanguage Collective LearnmoreaboutCollectivesonStackOverflow TheOverflowBlog Aconversationabouthowtoenablehigh-velocityDevOpscultureatyour... Podcast400:AnoralhistoryofStackOverflow–toldbyitsfoundingteam FeaturedonMeta NewresponsiveActivitypage PlannedmaintenancescheduledforThursday,16December01:30UTC(Wednesday... A/BtestingontheAskpage Related 2260 WhatareMVPandMVCandwhatisthedifference? 1913 Differencebetweenstaticclassandsingletonpattern? 338 What'sthedifferencebetweentheDependencyInjectionandServiceLocatorpatterns? 529 WhatarethedifferencesbetweenAbstractFactoryandFactorydesignpatterns? 219 DesignPatterns:FactoryvsFactorymethodvsAbstractFactory 0 Howisprototyperelatedtootherpatterns? HotNetworkQuestions DoesApacheWebserveruselog4j(CVE-2021-44228)? I'manabsolutebeginnerinbiketouring,abouttobuyabike.Isitworthittohireabikefittingservicebeforethepurchase? Whatisthis3-enginebeast? DrawphaseportraitwithStreamPlotonasphere Doanylanguagesusewordslikeparticlestorepresentcommas,periods,hyphens,quotes,parentheses,etc.? Doesachangelinggaintheabilitiesoftheraceitshapeshiftsinto? RhetoricaadHerennium-Englishtranslation Whywouldn'tallwizardsbebuff? Howmightnuclearpowerhaveneverbeendeveloped? WhatmusictheorypartsdoIhavetoknowbyhearttobeabletonamenotesinagivenchord? Identifythisset-bagswithwhite,grey,brownandbluebricks DoestheLog4jvulnerabilityaffectAndroidusers? InJohannineComma:ThreeareOne,orThreeinOne,orThreeinare? HowtopositionaTikZpicturerelativetotext? A"Thousandandonenights"semi-shortfantasyaboutadoortothepastorthefuture Recurrentdefinitionofalcoholcontentviahazing(5,2,9) ConsoleLibrarySysteminC++ Whycan'tyoumakecheesefromcoconutmilk? Arefront-endstatemanagementtoolsananti-pattern? XcodeWorkspace"Internalerror:missingPackageDescriptionModule" Candominatemonsteranddrowningbeusedasaninsta-kill? IsUbuntuitselfvulnerabletoLog4shell? AdvantageofSTFToverwavelettransform Whendoweneed'are'ingermansentences? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-golang Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?