--- Bob Jackman <[EMAIL PROTECTED]> wrote:

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

If I understand correctly, you want the actual object to be
either C1 or C2 depending on the parameters passed into the
constructor, right?  The short answer is that you don't do that:
"new A(blabla)" is going to return an instance of class A,
period. Constructors don't have a return value, so there's no way
around it.

The more helpful answer is that there are a variety of ways to do
what you want:

1) If you have the latest RB, you can define a class method
called NewInstance(par1, par2) that returns a new C1 or C2
instance depending on the params.

  Dim aInst As A = A.NewInstance(par1, par2)

2)  If you have an older version of RB that doesn't compile class
methods, you can make a module, call it "AFactory" for example,
and put your NewInstance method there.

  Dim aInst as A = AFactory.NewInstance(par1, par2)

3)  One of the above will probably work best, but there's always
the stand-by routine: just make NewInstance a regular method of
class A.

  Dim theFactory As new A
  Dim aInst As A = theFactory.NewInstance(par1, par2)



Mark Nutter

Quick and easy regex creation and debugging!
http://www.bucktailsoftware.com/products/regexplorer/

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
_______________________________________________
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