Path: news.daimi.aau.dk!news.uni-c.dk!sunic!news.funet.fi!news.csc.fi!news.eunet.fi!EU.net!howland.reston.ans.net!darwin.sura.net!RBSE.Mountain.Net!wvnvms!marshall.wvnet.edu!marshall.edu!hathawa2 Newsgroups: comp.object,comp.lang.eiffel,comp.lang.sather,comp.lang.beta,comp.lang.modula3 Subject: Re: Cows, Hogs & Farms Message-ID: <1995Jan13.211938@hobbit> From: hathawa2@marshall.edu (Mark S. Hathaway) Date: 13 Jan 95 21:19:38 EDT References: <1995Jan9.005627@hobbit> <1995Jan9.203528.29056@schbbs.mot.com> Organization: Marshall University Nntp-Posting-Host: frodo.marshall.edu Lines: 119 Xref: news.daimi.aau.dk comp.object:23835 comp.lang.eiffel:7189 comp.lang.sather:1434 comp.lang.beta:220 comp.lang.modula3:3332 > In article <1995Jan9.203528.29056@schbbs.mot.com>, > shang@corp.mot.com (David L. Shang) writes: >> In article <1995Jan9.005627@hobbit> writes: >>> In article <1995Jan6.164948.4782@schbbs.mot.com>, >>> shang@corp.mot.com (David L. Shang) writes: >>> ... >> So, ANIMALT.FOODT implies that a particular food is associated with a >> particular animal? How can it be a HERBIVORE and yet eat only one kind >> of plant? > It cannot be in reality. I am reluctant to complicate this example. But to > describe a HERBIVORE that eat more than one kinds of food is also possible > by multiple inheritance: > > class COW is HERBIVORE [ FOODT = GRASS ], > HERBIVORE [ FOODT = HAY ], > ... > > But there will be a problem when you try to substitude ANIMALT with COW: > > class MONOCULTUREFARM [ANIMALT <: HERBIVORE] > attr livestock : list[ANIMALT]; > attr foodstock : list[ANIMALT.FOODT]; > > cow_farm: MONOCULTUREFARM [COW]; > > As COW has multiple bases: HERBIVORE[GRASS], HERBIVORE[HAY], ..., which > base is used? You have to specify: > > grass_farm: MONOCULTUREFARM [COW as HERBIVORE[GRASS]]; > > or > hay_farm: MONOCULTUREFARM [COW as HERBIVORE[HAY]]; > > In fact, the MONOCULTUREFARM designed here is no longer suitable for an > animal that eats more than one plant, becase it only keeps one kind of > food. However, if we could figure out a subclass of PLANT for COW, say, > COW_FOOD, there is not problem to have HERBIVORE[COW_FOOD] and the > MONOCULTUREFARM as define above. > > Unfortuantely, in most cases, it is almost impossible to classify herbivores > according to the food type they eat. This is probably a bad example to > demonstrate the covariance. I whould like to use the herbivore/carnivore > classification example. The reason I continue to ask this question is that the first example I gave didn't bind the animal to the food. Someone added that later and confused the entire issue. See what a mess it makes? If you have... PLANT HERBIVORE _____| |_____ _____| |_____ | | | | CORN GRASS HOG COW I'm ignoring LIST | | | | for the moment. V V V V ----------- ---------- | HOG | | COW | | FARM | | FARM | |___________| |__________| it would seem much easier to bring the CORN & GRASS to mix separately rather than saying COW inherits HERBIVORE[GRASS] 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]; >> procedure feed ( get livestock is in out list(animal); >> get foodstock is in out list(food) ) is > Why should you provide additional input/output parameters for feed in > the class body? When I was creating this pseudo-code I noticed that there was the possibility for a class to have more than one piece of data which represented a part of the object and some of the data might be only supplementary or temporary. And, there is the question of whether all the data in a class should be considered globally shared with all the methods used by the class. I decided it would be interesting to add the "get" to bind a particular data to a method. It hasn't been roundly praised or condemned. Mostly people have asked why it's there. It's just an idea, not a lifestyle. :-) > Why should the feed interfaces be different? Only to specify those extra parameters with the "get"; which should remain unseen by the user who sees the interface. > Agian, I don't consider this herbivore example a good example to demonstrate > covariance. Lets just take the assumption that COW eat GRASS only and HOG > eat CORN only, and make things simple. If you don't like the assumption, we > may consider the animal/herbivore/carnivore example. Maybe someone could begin by defining "covariance" in words and/or with an example in code. Mark S. Hathaway