views:

60

answers:

1

Hi guys

I was wondering the differences between abstract and interface in actionscript 3 and when to use them..I have searched google but still couldn't understand them....I hope someone here can give me few tips...Thanks a lot!!!

+3  A: 

The difference is that interface is valid actionscript, but abstract is not...

Now, in other languages you can mark a method or a class as abstract. This is somewhat like an interface, in that abstract means it has no implementation (for a method) or cannot be instantiated (for a class).

So, if a class is abstract, it means you cannot create an instance diretly (with new), but rather you have to extend the class to access its functionality.

An abstract method is pretty much like a method defined in an interface. When you extend a class that declares an abstract method, you have to provide an implementation that has the same signature, or your code won't compile. An abstract method makes the class abstract automatically, because otherwise you would be able to create an instance of an object that has an unimplemented method.

With an abstract class, you have some of the features of an interface (i.e. you define a method whose concrete implementation has to be provided) but you also can have other methods that are implemented and ready to use.

(This is a general explanation; maybe this is bit different in language X, but I think this gives you the basic idea)

Juan Pablo Califano
Yep. @Jerry for example you might have a Shape class (not to be confused with the actual Shape class in AS3). This class would be a good candidate for an abstract class since it would have functions and properties shared for all of its subclasses (eg Circle, Square). Things like maybe colour, position, an unimplemented draw function. And since creating a shape itself makes no sense you would mark it as abstract so it could not be initiated directly, but rather only by a child like Rectangle etc - that is if AS3 supported abstract classes.
Allan
very nice.....thx guys..
Jerry