[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Yeah! I can convert!

>Excerpts from internet.info-macl: 27-Feb-92 Re: Yeah! I can convert!
Guillaume Cartier@math.u (3534)
>>My question is:  if the first thing you are going to do is call the
>>primary methods defined on the 'window class, why not code the
>>#'initialize-instance method on the 'shape-window class as an :after
>>method, and then simply remove the call to apply?  I believe this
>>would be both more efficient and conceptually correct, or am I 
>>missing something really important and/or really basic?
>>Thanks for your replies.  I realize that both implementations are
>>correct, in the sense that both "get the job done", but I am more
>>interested in learning good CLOS style and writing long-term maintainable
>>source code.  Thanks!
>>Luke Hohmann                       | hohmann@csmil.umich.edu
>>University of Michigan             | 313-763-1043 (Office)
>>Artificial Intelligence Laboratory | 313-677-0952 (Home)
>>1101 Beal Ave                      | 
>>Ann Arbor, MI 48109-2110           | "You should do more aerobics!"
>Here is a case where 'an AFTER method' and 'a primary method that first
>calls CALL-NEXT-METHOD' are not equivalent. It use multiple inheritance.
>I am not sure if this behaviour can occur when only single inheritance is
>used (maybe a CLOS wiz can answer this one).
>I am not sure what all this means and what is the "correct" way of doing
>things. It just shows that the two ways are not equivalent.
>It would be GREAT if someone else could shed some light on the pros and cons
>of both approachs.


>Hope this helps...
>Guillaume Cartier
>LACIM, Universite du Quebec a Montreal.
>Bureau: (514) 987-4290
>E-Mail: cartier@math.uqam.ca

An example:

Class A.
Class B is a subclass of class A.

If during the initialization of B, an operation defined in class A is
required, then class A must be initialized before any method calls to A.
 For example, if A is a list, and B is a queue, if the size of the list
is required in the initialization of B, and the operation is non-trivial
(for example, the list could be loaded upon initialization), then the
initialization of A must occur before the size method is called.

If class B overrides the operation of a method defined in A, then the
initialization of A must be called after the initialization of B, since
a class method of B may use potentially any of the method of the class. 
If an instance variable of the class is not initialized before the
method is called, the method may fail.  Therefore, since the
initialization of A may call any method overridden by B, the
initialization of B must be completed before the initialization of A.

Obviously, the initialization of A may not be called both before and
after the initialization of B.  Specific examples are quite difficult to
find.  As a general rule, any instance variables that are used by
methods of B that are overrides of methods of A must be initialized
before the initialization of A, since they may be called.  In addition,
no methods of class A may be called before the initialization of A is
called, for similiar reasons.

When using multiple inheritance, take all the superclasses of B as A. 
For a class structure {(A, D), (B, D), (C, D)}, where (X, Y) is a
superclass-subclass relation, X and Y are classes, treat the classes {A,
B, C} as a single class E, and define (E, D).  The initialization of D
cannot call any methods defined only in D until the instance variables
for those methods are initialized.  The initialization of {A, B, C} must
be called before any methods of {A, B, C} are called.