Tuesday, December 14, 2010

Curl ValueControl

Here's a challenge for class hierarchies without Traits.

The Curl class ValueControl is noted as follows in the docs:

ValueControl (class)
public abstract ValueControl {inherits Control}
Import from: CURL.GUI.STANDARD. Defined in package CURL.GUI.CONTROL-BASE.
Direct Known Subclasses: ValueControl-of
A superclass for any Control that has a value.
Description
All the Controls with values inherit from this class. It provides abstract accessors for the value, as an any, and an accessor for the expected Type of the value.
Overriding
Don't subclass this class. Subclass ValueControl-of instead.
I added emphasis to the advice. My question is, how might such an intent be enforced in a class hierarchy?  What would you call such a modifier or a macro used to create such a class?

The class in question has the 2 abstract methods value-type and value-as-any but it also implements 2 methods: form-value and has-value?.  In addition, it has a class procedure form-string.  The default constructor for the class is noted as
... : Rest arguments are passed up to Control, which passes them to Visual.
The method form-value is documented as intended for use with controls embedded in HttpForm instances.
It is documented as a getter but not as being abstract yet as intended to be overridden by subclasses.

Here is a snippet from those docs;
The value returned by this getter must be one of the following:
 • String
 • array of String
 • null
Notes
Each control overrides this method to return the value that needs to be sent when the HttpForm that contains this control is submitted.

So why is the method not abstract? Well, because it returns a value of type any - but its subclass is parameterized for types of values.  And here is one more thing that makes Curl fascinating: the leaf classes of these hierarchy branches are not themselves declared as parameterized for a type - and in the case of DateField, the value keyword parameter to the default constructor may be of a possibly-null type - a #DateTime type.

What this may show is that multi-inheritance with partially-abstract classes as mixins or otherwise can be very flexible:
public abstract MultiUIValueControlFrame-of {inherits 
   MultiUIControlFrame, 
   {ValueControl-of tValue}}

No comments: