Though I don't understand why do you need this kind of behavior (throwing
exception in constructor the way you do it) there's been quite a discussion
about abstract classes in AS3.
In flexcoders archives, you can find a lot of info and links to resources
devoted to this subject.
For not to go by without my 2 cents: as I see it in most situations all you
need is interface to implement by your class. It's more flexible than an
abstract class.
R.
On 6/28/07, Firdosh Tangri <[EMAIL PROTECTED]> wrote:
cool thanks guys ....I was trying a good way to figure out how to go
about abstract classes
so if the class is abstract I would do
public function AbstractList(){
throw new Error("Abstract class cannot be instantiated");
}
public function List(){
//what I need to
try{
super();
}
catch(err:Error){}
}
this seems to work fine
if anyone has a better suggestion I am all ears :)
cheers
firdosh
On 6/27/07, reflexactions <[EMAIL PROTECTED]> wrote:
>
> 'cos in every class unless you make an explicit call to super there
> is an automatic implicit call to super() before anything else
> executes in the subclass constructor.
>
> The explicit call to super can include params as in super(x) if the
> superclass has such a constructor.
>
> One gotcha is if you extend a class that has a constructor that takes
> an argument and decide not to override the constructor then you
> extend that class you cant call super with an argument anymore ie
>
> public class classA{
> function classA(xx:int){}
>
> ...other stuff...
> }
>
> public class classB extends classA{
> ...only other stuff is overridden...
> }
>
> public class classC extends classB{
> function classC(xx:int){
> super(xx);//compile error.... no such constructor in classB
> ..do some stuff..
> }
> }
>
> --- In [email protected] <flexcomponents%40yahoogroups.com>,
> "Firdosh Tangri" <[EMAIL PROTECTED]>
>
> wrote:
> >
> > hey guys
> > I have a class
> >
> > public class ClassA{
> >
> > public function ClassA(){
> > trace("classA constructor");
> > }
> >
> > }
> >
> > ===========================================================
> >
> > public class ClassB extends ClassA{
> >
> > public function ClassB (){
> > trace("classB constructor");
> > }
> >
> > }
> >
> > ===================================================================
> >
> >
> > when I do
> >
> > var c:ClassB = new ClassB();
> >
> >
> > why do both the statements get traced out even though I am not
> calling super
> >
> > cheers
> > firdosh
> >
>
>