Path: news.daimi.aau.dk!news.uni-c.dk!sunic!ugle.unit.no!trane.uninett.no!eunet.no!nuug!EU.net!howland.reston.ans.net!swrinde!ihnp4.ucsd.edu!network.ucsd.edu!mbk From: mbk@inls1.ucsd.edu (Matt Kennel) Newsgroups: comp.object,comp.lang.eiffel,comp.lang.sather,comp.lang.beta,comp.lang.modula3 Subject: Re: Cows, Hogs & Farms Followup-To: comp.object,comp.lang.eiffel,comp.lang.sather,comp.lang.beta,comp.lang.modula3 Date: 14 Jan 1995 23:22:07 GMT Organization: Institute For Nonlinear Science, UCSD Lines: 76 Message-ID: <3f9mav$7bf@network.ucsd.edu> References: <1995Jan13.211938@hobbit> NNTP-Posting-Host: lyapunov.ucsd.edu X-Newsreader: TIN [version 1.1 PL8] Xref: news.daimi.aau.dk comp.object:23850 comp.lang.eiffel:7192 comp.lang.sather:1436 comp.lang.beta:221 comp.lang.modula3:3333 Mark S. Hathaway (hathawa2@marshall.edu) wrote: : Also, notice that if you want a heterogeneous FARM you drop back to : using HERBIVORE, but a HERBIVORE isn't necessarily a COW or HOG. For : a heterogeneous farm you need LIST[COW] & LIST[HOG]. To create a : class which could represent either COW or HOG would be interesting. : I haven't seen any instances of that. What I have in mind is.... : -- HERBIVORE is the base class : COW is HERBIVORE; : HOG is HERBIVORE; : FARM_ANIMAL is COW or HOG; : FARM is LIST[FARM_ANIMAL]; -- Sather type $HERBIVORE is try(food:$PLANT); end; type $HERBIVORE{MYFOOD < $PLANT} is try(food:$PLANT); eat(food:MYFOOD); end; class COW < $HERBIVORE{GRASS} is -- blah blah blah implementation end; class HOG < $HERBIVORE{CORN} is -- implementation end; type $IOWA_FARM_ANIMAL > COW,HOG is try(food:$PLANT); end; class IOWAFARM is -- has hogs and cows. attr animals: LIST{$FARM_ANIMAL} attr food : LIST{$PLANT}; feed is loop animals.elt!.try(food.elt!); end; end; feed_corn is -- Cluster does this one a little cleaner loop f ::= food.elt!; a ::= animals.elt!; typecase f when CORN typecase a when $HERBIVORE{CORN} then a.feed(f); end; end; end; end; end; In general Cluster lets you get at the foodtype for animals for run-time selection OUTSIDE their class easily, in Sather it's usually easier to put the typecase inside the 'try'. : Mark S. Hathaway -- -Matt Kennel mbk@inls1.ucsd.edu -Institute for Nonlinear Science, University of California, San Diego -*** AD: Archive for nonlinear dynamics papers & programs: FTP to -*** lyapunov.ucsd.edu, username "anonymous".