In a Racket class system, what to do, increase, redefine, augride, etc.?

The racquet documentation only partially describes what augment and pubment : augment does a method that runs after the superclass version of that method, while pubment does a method that will implicitly have the augment property if it is defined in a child class.

The docs say absolutely nothing about overment and augride , and I cannot guess what they will do depending on their names. What are they, and what is the difference between them?

+5
source share
1 answer

The relatively large family of inheritance functions for the Racket class system, as you described, is a bit confusing, and their slightly prettier names do not always help.

To understand this, Racket provides two separate mechanisms for inheriting methods.

  • Methods
  • public follows the classical idea of ​​public methods in other OO models. Methods declared using public can be overridden in subclasses if they are not declared final, in which case they cannot.
  • pubment methods are similar, but they cannot be overridden, only extended. Augmentation of the method is similar to overriding, but sending will cause the implementation of a superclass instead of a subclass.

To clarify the difference between overriding and padding, when an overridden method is called, an overriding implementation is performed, which, if desired, can invoke the superclass implementation via inherit/super . In contrast, in an extended method, a superclass implementation gains control, and it may optionally invoke a subclass implementation through inner .

Now we are also provided with public-final , override-final and augment-final . It is pretty simple. Declaring a method using public-final means that it cannot be extended or overridden. Using override-final overrides the public method of the superclass, but this does not allow further overriding. Finally, augment-final similar, but for methods declared with pubment , not public .

So, what about two weird hybrids, overment and augride ?

  • overment can be used to implement methods originally defined using public . This "converts" them to extended methods instead of overriding methods for all subclasses of the class.
  • augride goes in the opposite direction. It converts the extended method to one of the overrides, but overriding implementations replace only the complement, not the original implementation.

Summarizing:

  • public , pubment and public-final all declare methods that do not exist in the superclass.
  • Then we have a family of forms to extend superclass methods:
    • override and augment extend the methods declared with public and pubment respectively, using the appropriate types of behavior.
    • override-final and augment-final do the same as their non-confidential copies, but prevent further redefinition or increase.
    • overment and augride convert augride methods to advanced methods and vice versa.

For another, more complete explanation, you might be interested in looking at the document from which the Racket model was derived , which is quite readable and contains some useful diagrams.

+7
source

Source: https://habr.com/ru/post/1216572/


All Articles