Newsgroups: comp.object,comp.lang.eiffel,comp.lang.sather,comp.lang.beta,comp.lang.modula3 Path: news.daimi.aau.dk!news.uni-c.dk!sunic!uunet!ftpbox!mothost!schbbs!news From: shang@corp.mot.com (David L. Shang) Subject: Re: Cows, Hogs & Farms Reply-To: shang@corp.mot.com Organization: MOTOROLA Date: Mon, 9 Jan 1995 20:35:28 GMT Message-ID: <1995Jan9.203528.29056@schbbs.mot.com> References: <1995Jan9.005627@hobbit> Sender: news@schbbs.mot.com (SCHBBS News Account) Nntp-Posting-Host: 129.188.128.126 Lines: 151 Xref: news.daimi.aau.dk comp.object:23594 comp.lang.eiffel:7135 comp.lang.sather:1403 comp.lang.beta:209 comp.lang.modula3:3314 In article <1995Jan9.005627@hobbit> writes: > > In article <1995Jan6.164948.4782@schbbs.mot.com>, > > shang@corp.mot.com (David L. Shang) writes: > > This form is slightly different in semantics from the Cluster's form: > > > > class MONOCULTUREFARM [ANIMALT <: HERBIVORE] > > attr livestock : list[ANIMALT]; > > attr foodstock : list[ANIMALT.FOODT]; > > ----- (1) > > Does Cluster separate the subtyping and inheritance as Sather does? > No. Subtype and subclass are the samething by Cluster. > Is the use of "ANIMALT <: HERBIVORE" a convenience or requirement? For a MONOCULTUREFARM classified by the type herbivore animals, using a class parameter "ANIMALT <: HERBIVORE" is a requirement, otherwise, a MONOCULTUREFARM will be a heterogenrous farm. > > 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, ther 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. > > Do any of these MONOCULTUREFARMs (Sather, Cluster or BETA) inherit > from FARM or are they the lowest base of farm that will exist in this > class hierarchy? > By Cluster, I guess BETA too, MONOCULTUREFARM[ANIMAT<:HERBIVORE] could be the lowest base of farm that exist in the class hierarchy. but no Sather, since a generci class is not a real class by Sather. We can have this hierarchy: (1)MONOCULTURE[ANIMAT<:HERBIVORE] (2)MONOCULTURE[ANIMAT<:HERBIVORE] (3)MONOCULTURE[HERBIVORE[PLANT]] (4)MONOCULTURE[COW] (5)MONOCULTURE[HOG] Note that ANIMAT is fixed to HERBIVORE[PLANT] in (3). It is a MONOCULTURE farm if we don't care the further division of the herbivores according to their animal food types. But we may still have an interest in the further division according to other things by adding addtional class parameters in subclasses. > How about... > > class MonocultureFarm ( food is plant, animal is herbivore ) is > procedure feed (); > end MonocultureFarm; > > class MonocultureFarm body is > import list; > object livestock is list(animal); > foodstock is list(food); > 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? Why should the feed interfaces be different? > begin > ... > end feed; > end MonocultureFarm; > > program temp is > import MonocultureFarm; > object myfarm is MonocultureFarm(corn,hog); How about: object myfarm is MonocultureFarm(corn,cow); if a cow dose not eat corn? > begin > myfarm.feed(); > end temp. > > Since it's not like a procedure within a module the parameters of > MonocultureFarm which are of type/class plant and herbivore aren't > "import"ed first. That's a little awkward, but these other languages > (BETA, Cluster, Sather) don't seem to need the "import". Is it no > longer regarded as necessary? > "import", or "use" decalrations is not the subject we discussed here. BETA and Cluster do need these declarations to have a complete program. > > If you're inheriting an HERBIVORE then how can it be an HERBIVORE that > only eats GRASS? Why not? Of cuase if you define a HERBIVORE that can eat ANY plant, a HERBIVORE that only eats GRASS cannot be a subclass. But if we define a HERBIVORE that can eat a certain type of food which is a subclass of PLANT, why cannot a HERBIVORE that only eats GRASS be a subclass? > > You can put a COW in a field of several plants, but you can't force it > to eat only GRASS. A HERBIVORE COW might choose to eat clover. 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. David Shang