Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!uunet!image.soe.clarkson.edu!news From: cline@cheetah.ece.clarkson.edu (Marshall Cline) Newsgroups: comp.object Subject: Re: Should Shapes Display Themselves? Message-ID: Date: 9 Aug 90 16:38:13 GMT References: <1681@dinl.mmc.UUCP> <25966@bellcore.bellcore.com> <10885@crdgw1.crd.ge.com> Sender: news@sun.soe.clarkson.edu Reply-To: cline@sun.soe.clarkson.edu (Marshall Cline) Organization: (I don't speak for the) ECE Dept, Clarkson Univ, Potsdam, NY Lines: 40 In-reply-to: halvers@altair.crd.ge.com's message of 9 Aug 90 14:42:10 GMT In article <10885@crdgw1.crd.ge.com> halvers@altair.crd.ge.com (Pete Halverson) writes: >In article cline@sun.soe.clarkson.edu (Marshall Cline) writes: >>QUESTION: Should a `Shape' be able to `draw' itself? >>The usual answer is ABSOLUTELY....However: what if I add a new terminal >>type? Or what if I want a textual `view' (using MVC terminology) rather >>than a graphical `view'? >CLOS explicitly deals with this kind of "orthogonal polymorphism" in the >form of multimethods, in which behavior can be dependent on any or all of >the arguments, not just the first. [...] > (defmethod draw ((shape square) (view text-view)) > ;; print "I'm a square" > ) > (defmethod draw ((shape square) (view graph-view)) > ;; render square > ) Ok, you can get this sort of thing in C++ with a bit of code bloat by top-level functions and exact matches on both parameters [however the CLOS scheme is more general in general :-) since it has multiple polymorphism where C++ uses a `compile-time-best-match' scheme]. Furthermore the top-level function can be a `friend' of `Square' so it can get at the Square's "I am a Square" name and/or vertices etc. But this brings us back to ``operating on objects'' rather than empowering objects to do things for us. Would double dispatching allow this to be expressed better? Marshall Cline -- ============================================================================== Marshall Cline / Asst.Prof / ECE Dept / Clarkson Univ / Potsdam, NY 13676 cline@sun.soe.clarkson.edu / Bitnet:BH0W@CLUTX / uunet!clutx.clarkson.edu!bh0w Voice: 315-268-3868 / Secretary: 315-268-6511 / FAX: 315-268-7600 Career search in progress; ECE faculty; research oriented; will send vita. PS: If your company is interested in on-site C++/OOD training, drop me a line! ==============================================================================