Why are there different ways to describe same design pattern ...

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

refactoring guru is also a good choice. They opted to use interfaces instead of abstract classes, which is fine. But they have redefined the ... 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 WhyaretheredifferentwaystodescribesamedesignpatternusingUML?Whattotrust? AskQuestion Asked 3monthsago Active 3monthsago Viewed 70times 2 IfinditdifficulttolearnbothDesignPatternandUMLsincetherearedifferentwaystodescribethesamepatternwhichmakemeunsurewhatisthesinglesourceoftruth. TakeIteratorpatternforexample,herearejustafewdiagramsthatIsawfromwell-knownsites: 1WIKIPEDIA https://en.wikipedia.org/wiki/Iterator_pattern 2TUTORIALSPOINT https://www.tutorialspoint.com/design_pattern/iterator_pattern.htm 3REFACTORINGGURU https://refactoring.guru/design-patterns/iterator 4OODESIGN https://www.oodesign.com/iterator-pattern.html 5HOWTODOINJAVA https://howtodoinjava.com/design-patterns/behavioral/iterator-design-pattern/ Whatconfusesmethemostishowarrowsymbolsareusedtodescribetherelationshipbetweentheseclasses.Sometimestheyaregeneralization,sometimesinterfacerealization,directedassociationordependency.Evencompositionisalsoused... Iwonderwhatwouldbethebestwayformetogetmyheadaroundallthis. design-patternsiteratorumlsoftware-designclass-diagram Share Follow editedAug31at0:11 Christophe 58.2k55goldbadges5959silverbadges115115bronzebadges askedAug30at20:49 GreatQuestionGreatQuestion 2,14266goldbadges3131silverbadges4343bronzebadges 2 2 BuytheDesignPatternsbyGammaetal.They"invented"itandshouldberightaboutthenotation(TM).It'sthefirstsourcementionedintheWikiliterature. – qwerty_so Aug30at22:00 1 Thattutorialspointisplainwrong.Theyusenamedassociationsinsteadofrealizaion/generalization.That'sacompletelydifferentthing.NotsureaboutwhichofthelatterisusedbyGamma;theyhavedifferentmeaning. – qwerty_so Aug30at22:07 Addacomment  |  1Answer 1 Active Oldest Votes 3 Ingeneral,oneneedstobeverycarefulwhenlookingatUMLmodelsfordesignpatterns.Therearethreereasons: ThereferencefordesignpatternsistheGoF.Thisbookwaspublishedin1995,beforeUMLevenexisted,andusedavariationoftheOMTnotation(anancestorofUML).Incaseifdoubts,thisisthesourcetotrust. TheJavalanguagedesignwasmadepublicin1995,JDK1.0releaseinJanuary1996,andthelanguagenotyetwidelyknown.TheauthorsbasedtheirdesignsandcodeexamplesonaC++classmodel,i.e.onclassesandinheritanceonly,withoutbotheringformultipleinheritance.Mostmodernlanguagesdonotsupportmultipleinheritance.Asaconsequence,someoftheoriginalpatternshavetobeadaptedforJava,C#orSwift,tomakeadistinctionbetweenclasses,abstractclassesandinterfaces,andbetweeninheritanceandinterfaceimplementation.Therearemultiplewaystodothis.Forexample,somesystematicallyconvertedabstractclassestointerfaces.Someconvertedthemonlywhentherewasaconflict.Andsomeconvertedaccordingtotheinterface"spirit". Misunderstandingshappen.Somepeoplepublishsuchdiagramsonthenetbutmisunderstandthepattern,ormisunderstandUML,orbothtogether.Also,GammaetalstartedthebookwhentheywerePhDstudentsandalsomadesomemistakes.You'llfindforexamplesomeinconcsitenciesintheiruseoftheOMTaggregation. TheworstcaseistheBuilderpattern,whereyouhavenotonlythoseproblems,butontopofthatyouhaveanamingconflict:averypopularJavabookintroduceda(verydifferent)variantofthebuilderpattern,withadifferentintentandanotherdesign,whichcausedtotalconfusion. Nowtoyourspecificexample,andbasedonthecontentyouhaveprovided: oodesignistheclosesttotheoriginalpatternandfullyaccurate.Btw,Imostlyuselinkstotheirpageswhenitcomestopatterns. refactoringguruisalsoagoodchoice.Theyoptedtouseinterfacesinsteadofabstractclasses,whichisfine.Buttheyhaveredefinedtheinterface'soperationsandproperties(probablyinrelationtoownexamples)andrequireabidirectionalnavigationthatseemsnotjustified.Ifyou'reinterested,thereisa"HeadFirst:Designpatterns"whichusesasimilarmappingbutkeepstheoriginalinterface. wikipediaisnotbadeither:theyhaveleftouttheclient(whichtheGoFshowedinlightgray,tosuggestthatit'snotessentialforthispattern);Theyaremorepreciseandcompleteondependencies;Buttheyalsoredefinedtheoperationsandpropertiesdifferently.Andtheyaddedanunnecessaryaggregationsymbol. HowtomakeitinJavaisconfusing,becausetheykeptoneabstractclassandoptedforaninterfacefortheother.Andtheyhavehiddentheoperationsandproperties.Butthere'snothingfundamentallywrongatfirstsight. Forgetabouttutorialpoints,atleastforthisUMLdiagram.It'splainwrong,as@qwerty_soalreadymentionedinthecomments. Thestatementofaccuracyisforthispatternonlyandforthecurrentversionofthecontent.Thiscannotbegeneralizedtoallthedesignpatternsinviewofmyintroductoryremarks. Share Follow editedAug31at8:47 answeredAug30at23:42 ChristopheChristophe 58.2k55goldbadges5959silverbadges115115bronzebadges 8 TheGoFbookwasoriginallypublishedinOctober1994andJavawasnotmadepublic(i.e.outofbeta)untilJanuary1996.ThetimingofJava'sreleaseisn'tnecessarilygermanetothequestion,sinceitisn'ttaggedassuch.Itonlyemphasizesthepointthatthematerialinthebookissignificantlyolderthanmost"modern"languages. – jaco0646 Aug31at0:21 It'salsoimportanttomentionthatjustbecauseawebsitehappenstobemoreaccurate(today)withrespecttotheIteratorpattern,thatdoesnotmeanthesamewebsitewillbeaccuratewithrespecttoanotherpattern.Inmyexperience,Wikipediahasbeenverypoorwiththeaccuracyofdesignpatternarticles(andalsotendstochangeovertime).Evenafter25+years,thebookitselfisstillthemostaccuraterepresentationofwhatitsauthorsintended.Allofthesewebsiteswillhavesomeinconsistencies,somemorizingthepatternsisnotsufficient.Understandingtheirintentiscritical. – jaco0646 Aug31at0:42 1 @jaco0646Ifullyagreewiththeaccuracyofwebsites.Wikipediaisgenerallypoor.Andoodesignrelativelygoodalthoughnotperfect.Andindeed,thebestresourceisstilltheGoF,whichalsoaddressessomeopenquestionswithpros/conswhereaswebsitesveryoftentakepositiononthosequestions,thispresentingapartialviewoftheoriginalcontent.LongliveGoF!(ifonlys.o.couldupdatetheoutdatedexamples);-) – Christophe Aug31at0:57 1 Well,thatmademeagoodhistorylesson:-)IwonderwhythereisnoUMLupdateontheGoFbook,oristhereone? – qwerty_so Aug31at9:01 1 It'snowalmostanother15years.Iwouldn'texpectanyupdatethen.Probablythelotof"Designpatternsfor..."bookswouldmakeamarketfor"Designpatternsforbooksondesignpatterns"? – qwerty_so Aug31at13:31  |  Show3morecomments 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?Browseotherquestionstaggeddesign-patternsiteratorumlsoftware-designclass-diagramoraskyourownquestion. TheOverflowBlog Aconversationabouthowtoenablehigh-velocityDevOpscultureatyour... Podcast400:AnoralhistoryofStackOverflow–toldbyitsfoundingteam FeaturedonMeta NewresponsiveActivitypage PlannedmaintenancescheduledforThursday,16December01:30UTC(Wednesday... A/BtestingontheAskpage Related 96 InUMLclassdiagrams,whatareBoundaryClasses,ControlClasses,andEntityClasses? 248 WhatisthedifferencebetweenStrategydesignpatternandStatedesignpattern? 198 Whatisthefacadedesignpattern? 529 WhatarethedifferencesbetweenAbstractFactoryandFactorydesignpatterns? 0 PHPAbstractFactoryPatternImplementation 0 Commandpatternforrestaurantusecase 2 WhatistherelationshipcorrespondingtoimplementationinheritanceinUML? HotNetworkQuestions Whyisthereonefewersolardayperyearthantherearesiderealdays? DoesApacheWebserveruselog4j(CVE-2021-44228)? Whyisitnotpossibletogettheprivatekeyoutofthepublickey WhatexactlywasEastPrussiabetween1933and1945?Wasitpartofalargergovernment,andwhichone? AoCG2021Day14:Adjustingdancingprogram'speriod Whyisthispositioninthe3.d4d5Petroffequal? Candominatemonsteranddrowningbeusedasaninsta-kill? Identifythisset-bagswithwhite,grey,brownandbluebricks Whynotextendthedownwindwhenfirstlearningtoland? Howmightnuclearpowerhaveneverbeendeveloped? Whyisneutralitysoimportantinavoltaiccell? WereOttoOctavius'sextraarmscontrolledbyanAIorusedasanextensionofhisownmind? Howtoplayatremolobetweenarestandanote?(pianosheet) Howdoesthelog4shellvulnerabilitywork? AoCG2021Day15:LeapfrogSanta Stainsingrout Wouldabrokenarm/legbemorepainfulinzerogravity? HowcanIunderstandwhethermyCimplementationisconstant-timeornot(i.e.resistanttotimingattacks) Howtoavoidevolutionforalanguagemadetobespokenacrossanentiregalaxy? Whatisthisseddoingwiththescript:`$a\`? CanGodactagainstHiswill? Isitascamifanon-AmazonmerchantsendstwoitemsfromAmazonwhenIorderedone? Withoutsaying"crossproduct"explainwhythereisaskew-symmetricangularmomentumtensor Whataresomeinteresting/importantProgrammingLanguageConceptsIcouldteachmyselfinthecomingsemester? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?