| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (10 out of 12)

Duplicate Methods

Sometimes the nature of an operation requires it to do slightly different things under different circumstances to operands of the same class, and these differences require supplying the relevant method with different numbers of arguments. To provide for such cases, G2 allows you to define methods that:

For brevity, G2 refers to such methods as duplicate methods, even though only the methods' qualified names are duplicates, and not the methods themselves.

For example, suppose that in the vessel example, you sometimes want to supply the label to be pasted onto a flask, and other times want a default label. You could define a second fill method on flask.

fill (F: class flask, L: class label)
Sterilize the flask, execute call next method to fill the flask, than paste the label on the flask.

With both fill methods defined, G2 counts the arguments each time you invoke fill on a flask, and selects the fill method that has that number of arguments.

Duplicate and Superior Methods

When you use call next method in a duplicate method, you must make sure that the superior method is also duplicated, or G2 will not invoke it because it has the wrong number of arguments. For example, the two-argument flask::fill in the preceding example would not work correctly unless a two-argument vessel::fill existed also.

When duplicate superior methods exist, you must use call next method to invoke the correct superior method. Trying to call it directly may invoke the wrong method, as in the case of duplicate procedures, resulting in an error due to mismatched argument lists. For further information, see Duplicate Procedure Names.

| Prev | Next | Start of Chapter | End of Chapter | Contents | Glossary | Index | Comments | (10 out of 12)

Copyright © 1997 Gensym Corporation, Inc.