Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!crdgw1!altair!halvers From: halvers@altair.crd.ge.com (Pete Halverson) Newsgroups: comp.object Subject: Re: Should Shapes Display Themselves? Message-ID: <10885@crdgw1.crd.ge.com> Date: 9 Aug 90 14:42:10 GMT References: <1681@dinl.mmc.UUCP> <25966@bellcore.bellcore.com> Sender: news@crdgw1.crd.ge.com Reply-To: halverson@crd.ge.com (Pete Halverson) Organization: General Electric Corporate R&D Center Lines: 46 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. Thus, one can define a method for each combination of shapes and view types (at whatever level of abstraction is necessary). For instance, given a class structure like (defclass shape () () (:documentation "base shape class")) (defclass square (shape)) (defclass circle (shape)) (defclass hexagon (shape)) (defclass view () () (:documentation "base view class")) (defclass text-view (view)) (defclass graph-view (view)) you could define multimethods like (defmethod draw ((shape square) (view text-view)) ;; print "I'm a square" ) (defmethod draw ((shape square) (view graph-view)) ;; render square ) ...etc. -- =============================================================================== Pete Halverson INET: halverson@crd.ge.com GE Corporate R&D Center UUCP: uunet!crd.ge.com!halverson Schenectady, NY "Money for nuthin' and your MIPS for free"