From: Patrick A. O'Donnell

Subject: Re: Different argument list for same method name

Date: 2000-11-14 10:12


    Date: 	Tue, 14 Nov 2000 12:15:23 +0100 (CET)
    From: David Kaasen <nvg.ntnu.no at kaasen>

    I am writing a program in LISP, using CLOS. I designed
    two independent classes, both with a method called 'add'.
    The problem is, the argument list of the two add methods
    is different, which is not allowed in CLOS.

Two suggestions:

First: avoid the seductive trap of confusing overloading with
genericity.  Define the contract for your generic function ADD, then
the correct argument list should be clear.  You will then be able to
define the methods for each of your classes.  If the two methods are
really honoring the same contract, then there should be no problem; if
different argument counts are really appropriate then optional,
keyword, or rest arguments may be the answer for you.

    Of course a solution could be to give the methods different
    names, but I think that is unsatisfactory.

If the two methods are implementing different contracts or
specifications, then different names would be appropriate.

Second suggestion: in CLOS, prefer to think of methods as associated
with generic functions rather than classes.  Methods are specialized
on their arguments: method selection is really choosing which
specialized function for the generic is appropriate, given the
arguments supplied at run time.

		- Patrick A. O'Donnell
		  <ascent.com at pao>