What is the difference between AbstractList and:

class NotExactlyAbstractList extends AbstractList {
   public function NotExactlyAbstractList() {
       try {
           super()
       } catch(e:Error) {}
   }
}

I instantiate NotExactlyAbstractList and get the very same AbstractList. Of
course if compare by functionality. In general it's far from AbstractList,
as far as subclass can be. However in either situation "abstract" is more
the matter of style and convention.
Because if, say some novice developer will subclass AbstractList and will do
it in simple straightforward way:

class CoolList extends AbstractList {
   public function sayHelloList() : void {
       Alert.show("Hello, List!");
   }
}

After

var coolList : CoolList = new CoolList();
coolList.sayHelloList();

He will get the very same vague exception. "But how is it possible?"- he
will think: "I've created and instantiated specific class. And what's that
abstract class anyway? I'm coding AS3, ain't I?" :)
That's how I see it. Hope I'm not that totally wrong. :)

R.

On 6/28/07, Firdosh Tangri <[EMAIL PROTECTED]> wrote:

  well this is so that you can create a interface say List
have an abstract class AbstractList implement the common methods
and then say VectorList extends AbstractList which implements all the
methods

but the user cannot instantiate a Abstract class object

so although he can now do

var t:VectorList = new VectorList();

var t:AbstractList = new AbstractList (); will throw an error so the
developer will know not to use this class by itself




On 6/27/07, Roman Protsiuk <[EMAIL PROTECTED]> wrote:
>
>   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
> > > >
> > >
> > >
> >
>

Reply via email to