Hi,

If you "type" as a superclass you are generally programming to an interface, so you can just as easily type to an interface.

Using interfaces is generally more flexible - it's easier to work with "has a" (interfaces) than "is a" (subclass), but sometimes you need a default implementation for your interface, which is why there are a number of abstract classes in AS3 that implement the interface - you need some generic behaviour, it can go in a super-class, but concrete classes are often difficult to deal with when you want to swap between interfaces.

E.g. unlike C++ with multiple inheritance, you can only extend a single class, but you can implement as many interfaces as you want. People will generally tell you to work with interfaces, but there are times - and you will find out somewhere along the line, where only a superclass will do.

For a simple example of this, look at what we do with Sprites and MovieClips when we extend them.

Hope this helps. If you have not looked at "Head First Design Patterns", or a similar book about patterns, then they will give you a more in-depth grounding than I can.

    Glen

On 23/09/2010 17:42, Doug Lambert wrote:
Inheritance and abstract classes

The examples I've seen are set up this way:
Super class (abstract class) contains all methods
Subclass overrides methods in super class
Class instances are typed as super class and instantiated as subclass.

I'm wondering why the examples show instances typed as a super class and 
instantiated as a subclass. This makes it necessary for all methods to exist in 
the super(abstract) class and overridden in the subclass. Is this on purpose so 
the abstract class acts as an interface? Wouldn't it be more flexible to type 
and instantiate as the subclass so methods can be added to the subclass that 
don't exist in the super(abstract) class?

I like the idea of abstract classes. I'm just trying to figure out the best way 
to use them.

Thanks.



_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to