home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!cs.utexas.edu!usc!sdd.hp.com!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.object
- Subject: Re: Object-Oriented Methodologies - Class Specifications
- Date: 12 Sep 1992 03:20:37 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 30
- Message-ID: <18rnm5INNisq@early-bird.think.com>
- References: <715276480.1.p00058@mail.psi.net> <1992Sep2.135247.11696@bcrka451.bnr.ca> <5740@osc.COM>
- NNTP-Posting-Host: telecaster.think.com
- Keywords: signature
-
- In article <5740@osc.COM> Joe Keane <jgk@osc.com> writes:
- >Suppose that there are well-known classes A and B, and a method M which
- >operates on instances of both. Initially there is an implementation for
- >M(A,B) and we want to see how people can override this implementation. Now
- >suppose that person X makes a class AX which is a subclass of A. Then he can
- >write a new implementation for the combination M(AX,B). Similarly, person Y
- >makes a class BY which is a subclass of B, and also writes an implementation
- >for the combination M(A,BY).
- >
- >So what happens when the method M is called with the combination M(AX,BY)?
-
- Yes, this can be a problem. The solution CLOS takes is arbitrary, but
- pretty simple: there's a precedence order to the arguments (left-to-right
- by default, but the definition of a generic function can override this).
- So, in the default case, M(AX,BY) would invoke M(AX,B); if it calls
- CALL-NEXT-METHOD this will invoke M(A,BY), and if this calls
- CALL-NEXT-METHOD it will invoke M(A,B).
-
- Things are simplified if the classes are defined in mixin style, using
- :BEFORE and :AFTER methods for the X and Y mixin classes, rather than
- shadowing the M method totally. In that case, the standard method
- combination facility will arrange for all the methods to run automatically.
-
- The metaobject protocol can be used to define other conflict resolution
- schemes, including signalling an error due to the ambiguity.
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-