> I have a superclass, let's say it's Dog.  Then, I have some extensions of 
> Dog, like so:
> Schnauzer extends Dog
> Poodle extends Dog
>
> In the Dog constructor, I want to prevent a Dog from being instanced 
> directly, but when I include this line in the
> superclass constructor:
> throw new IllegalOperationError("Class must be instanced through one of Dog's 
> subclasses.");
>
> ...all the base class instances throw the error.  How best to prevent the 
> superclass from being instanced on its own?

AS3 doesn't support abstract classes, only interfaces. You can either
use interfaces instead, or do this:
http://joshblog.net/2007/08/19/enforcing-abstract-classes-at-runtime-in-actionscript-3/

... which is basically what you're doing with a little modification.
You have to have something you can look at during instantiation of the
superclass that's only provided by the subclasses.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to