From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_05,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,47def5aa7b3182bd X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: How to write TYPECASE in Ada 95? Date: 1999/02/18 Message-ID: #1/1 X-Deja-AN: 445656443 Sender: matt@mheaney.ni.net References: <79fct8$9k3$1@murdoch.acc.Virginia.EDU> <1103_918264881@DZOG-CHEN> <36cb2712.1390453@news.pacbell.net> <36cbb8b3.35099816@news.pacbell.net> NNTP-Posting-Date: Thu, 18 Feb 1999 03:15:31 PDT Newsgroups: comp.lang.ada Date: 1999-02-18T00:00:00+00:00 List-Id: tmoran@bix.com (Tom Moran) writes: > >If you want to extend a type with arbitrary behavior, you could take a > >look at using the Visitor pattern. Ada implementations of this pattern > >are available at the ACM patterns archive. > > > > Am I looking at the right place? I see > > >package body Equipment.Pricing is > > > > function Get_Total_Price > > (Equipment : Root_Equipment'Class) return Dollars is > > begin > > if Equipment in Floppy_Disk then ... > which surely looks pretty similar to > > > procedure Serve_Fruit(Dish : in Fruit'class) is > > begin > > if Dish in Apple'class then Serve(Apple(Dish)); > > ... > > elsif Dish in Watermelon'class then Serve(Watermelon(Dish)); Indeed, you are correct. The was the last of 3 versions of the visitor pattern I sent to the list, and I discuss the pros and cons of each approach in the accompanying text.