On Dec 6, 2006, at 5:25 PM, Bob Jackman wrote:

I have two questions based on the following setup:

I have 1 superclass A which is subclassed by classes C1 anc C2.

***Question 1

I would like to use A as a Factory to create the correct C1 or C2 subclass.


dim x as new A(par1, par2) //where par1 and par2 are some parameters

How can I do this in the constructor of A?

You can't. Instead, add a shared method NewObject() as A to A. In this method, you can create either a C1 or a C2. The syntax for calling a shared method looks like this:

dim foo as A = A.NewObject

You might want to document whether or not NewObject should always return a non-nil object.


***Question 2

After creating a new A instance shown above, I would like to put that
instance into an array or other As.  Easy enough

Dim AArray(-1) as A
AArray.Append(x)

However I would then like to call a method like

AArray(0).Foo(para1)

where Foo is defined in C1 and C2. The right C1 Foo or C2 Foo would be called based on which class was instantiated from the proper process in
Question 1.  However when I try to type:

AArray(0).

I do not get the option of the Foo method with the smart method fill in. Just to clarify Foo is defined in C1 and C2 and Foo is not defined in A.


If Foo is not defined in A, then the compiler doesn't know about it. Define a stub or abstract method A.Foo, and override it in subclasses.

Charles Yeomans
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to