Showing posts with label Mixins. Show all posts
Showing posts with label Mixins. Show all posts

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}}

Monday, December 13, 2010

Curl BaseFrame

The Curl class BaseFrame is declared as
public BaseFrame {inherits BasicBox}
and is not abstract. Frame inherits from it as
public Frame {inherits BaseFrame}
and is certainly not abstract. But a RootFrame to root a graphic hierarchy is declared as
public abstract sealed RootFrame {inherits Frame}
and is abstract -yet its immediate subclass View is declared as
public View {inherits GuiRangeSelectionContext, RootFrame}
and is a very common class for concrete instances.  GuiSelectionRange is also abstract and is declared as
public abstract GuiRangeSelectionContext {inherits TextSelectionContext, BaseGuiRangeSelectionContext, ContainerDragScroller, OptionListInterface}
RootFrame and GuiRangeSelectionContext are performing a special role that Traits or Mixins might perform in another language.

View has a need to have its visibility specified as a property, which can be a stumbling block in first experiments with Curl. Here is an example:

{curl 7.0 applet}
{import WindowVisibility from CURL.GRAPHICS.WINDOW}
{View visibility=WindowVisibility.normal,
   {text Some text that will appear in a freestanding window}
}

View has an interesting subclass which is rather like the first window one used to create for MS Windows back in the days of C using only a frame: OutlineOnlyView.

BaseFrame is a usable class, which is not what the name would suggest in some other languages: it is usable in the sense that a subclass can make immediate use of its constructor in a class declaration as shown in the Curl docs:
{constructor {default}
     {construct-super.BaseFrame
which the docs say can be used as a special frame destined to have only one child graphic or visual object.