Hi Darren,
I assume you were reading my coding standards article. If you are only
using MTASC you won't have the problem with using Object as type, so you
won't have to bother. But if you want your project to be compilable with
Macromedia's Compiler you'll have to bother.
The following example will raise a compile error with MMC:
class MyClass {
public function doSomething(object:Object):String {
if (object implements MyInterface) {
return MyInterface(object).getStringRepresentation();
}
return object.toString();
}
}
interface MyInterface {
public function getStringRepresentation(Void):String;
}
class AnotherClass implements MyInterface {
public function getStringRepresentation(Void):String {
return "AnotherClass";
}
}
var instance:MyClass = new MyClass();
var myParameter:MyInterface = new AnotherClass();
instance.doSomething(myParameter);
Simon
Darren Cook wrote:
>I've been reading a set of Actionscript 2 coding standards (*) and am
>confused a bit by this one: do not use "Object" as return type (or
>parameter type) when the value can be of any type. This is because "the
>Macromedia compiler thinks that instances casted to interfaces are not
>of type Object".
>
>I find using "mtasc -strict" very useful, but then leaving off the
>return or parameter type is not possible.
>
>I must admit I don't quite understand what the above means - can someone
>provide an example of "instances casted to interfaces"? Does mtasc have
>the same problem as the Macromedia compiler?
>
>Darren
>
>*: http://www.simonwacker.com/blog/archives/000087.php
>
>_______________________________________________
>osflash mailing list
>[email protected]
>http://osflash.org/mailman/listinfo/osflash_osflash.org
>
>
>
>
--
Simon Wacker
www.simonwacker.com
www.as2lib.org
www.hq-heilbronn.de
www.flik-flak.de
_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org