I was studying up on the MzScheme OO library (for some potential MrEd development) and came across the pubment method decleration. I know all about public, private and protected - but pubment?
It's a pretty slick concept, check it out:
The stack% class declares its print-name method using pubment, which means that the method is public, but it can only be augmented in subclasses, and not overridden. The implementation of print-name uses inner to execute a subclass-supplied augmenting method. If no such augmenting method is available, the (void) expression is evaluated, instead. The fancy-stack% classes uses augment to declare an augmentation of print-name, and also uses inner to allow further augmenting in later subclasses.
pubment appears to allow you to write a method, and yet give your subclass a way to intervene, in a controlled way, during the method execution. The result is that your subclass can provide functionality without it having to re-implement or delegate to, an entire method.
Interesting.
I find this fascinating, and useful, not because it's Scheme and Just Better, but because it reminds me that there's more to OO than what Java or C++ decides is OO. It's also a powerful reminder of what happens when your OO framework is a user-level add-on, and not a core part of the language. Programmers will not only come up with novel OO conventions, but will also be able to implement them fairly easily.
A poweful lesson, if you ask me.
I wonder how pubment compares to Aspect Oriented Programming. Guess I could try that in MzScheme too.
No comments:
Post a Comment