A couple of examples of polymorphic lists in PowerBASIC. The first example creates a simple list of animals of different types and then listens to them.
The second example manages a list of shapes. Adding a new type of shape is a two step process: 1) Define a class implementing iShape. 2) "Register" the new class by adding an instance of it to masterList. Everything else is handled from there. You can create new instances of any registered shape. Edit the properties. Save a set of shapes to disk, load a set of shapes from disk, clear the shape. To open a shapes editor simply click on it. The shape will be highlighted along with displaying a properties dialog.
Here's an example of registering a shape:
shape = Class "cCircle": masterList.Add( shape )
The shape interface has the following properties and methods:
Interface iShape
Inherit IUnknown
Property Get Type() As String - Returns the name of the type, for example circle.
Property Get Settings() As String - Returns the values for the shape as a string, for example circle,5,5,20. The first value must define the type of the shape.
Property Set Settings( value As String ) - Sets the values for the shape from a string
Method Draw( Optional ByRef clr As Dword ) - Draws the shape on the currently attached graphic control, you can optionally pass a color.
Method Edit() - Edits the shapes values. Define a child dialog and use the view manager to display it.
Method New( ByRef obj As iShape ) - Factory method to create a new instance.
Method Hit( ByVal x As Long, ByVal y As Long ) As Long - Test if the shape was hit by the x,y
End Interface