Smalltalk and Python
Quinn Dunkan
quinn at dinar.ugcs.caltech.edu
Thu Dec 14 15:29:58 EST 2000
More information about the Python-list mailing list
Thu Dec 14 15:29:58 EST 2000
- Previous message (by thread): Smalltalk and Python
- Next message (by thread): Smalltalk and Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, 14 Dec 2000 13:25:51 +0100, Alex Martelli <aleaxit at yahoo.com> wrote: >"Ian Wild" <ian at cfmu.eurocontrol.be> wrote in message >news:3A389B1A.4F33FFD4 at cfmu.eurocontrol.be... >> Alex Martelli wrote: >> > >> > I can't find a source any more, but one of the most interesting >> > arguments I've heard for "only inherit from abstract classes" >> [...otherwise...] >> > it would break the idea that your concrete >> > classes partition the universe of discourse, if it were. >> >> Where does this partitioning requirement come from? > >From the fact that an object 'is an instance' of one, >and only one, class -- 'THE class' (singular) 'of the >object'. If an object 'belongs' to n>1 classes, in >this framing, this is modeled by having the (inevitably >singular) class 'of the object' _inherit_ from the >said n>1 classes (i.e., 'belongs' is a weaker relationship >than 'being an instance of'). > >I am not aware of any OOA approaches in which is-instance-of >(as here defined) isn't an exhaustive and many-to-one >relationship between objects and (concrete) classes; >in other words, OOA approaches which let some objects >(in the universe-of-discourse that is being modeled) >be an instance of 'no class', or of several classes >at the same time. Well, I'm not quite sure if it's what you're talking about (all this high falutin' "OOA" stuff tends to zip by over my head), but perhaps haskell's typeclass system is like this. In haskell, a class describes an interface, and any type that supplies that interface can function as an instance of that class. So: data Rectangle = Rect Int Int data Sailor = Sailor String data Poodle = Poodle String class Drawable t where draw :: t -> String class Pirate t where pirate_talk :: t -> String instance Drawable Rectangle where draw (Rect x y) = "a rectangle with sides " ++ (show x) ++ " and " ++ (show y) instance Drawable Sailor where draw (Sailor name) = "a sea-dog named " ++ name instance Pirate Sailor where pirate_talk (Sailor name) = name ++ " growls, 'arr, matey!'" So, a Rectangle is an instance of Drawable (so it will be accepted by any function that wants a Drawable type), a sailor is an instance of both Drawable and Pirate, and a Poodle not an instance of any class (so it will only be accepted by functions that want a Poodle type). No inheritance is involved. Or maybe you're saying there is no developed method of analysis for this sort of thing. It would surprise me if there weren't, since they're a pretty academic bunch over there in FP-land :)
- Previous message (by thread): Smalltalk and Python
- Next message (by thread): Smalltalk and Python
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list