1
votes

I'm using Adobe's CS Extension Builder, and I've abstracted away concrete implementations of certain classes with interfaces, to enable testing.

How do I then cast the API classes to the interface? I though with AS3 being a dynamic language, doing it like: "Application as IApplication" would work, but it doesn't. Note that the interfaces specify what is in those implementations and nothing more, so from a dynamic point of view it should work.

I tried the following as suggested, but it leaves iApp null. It may be that one of the properties in the interface returns a concrete type in Application, but again uses an interface for abstraction purposes.

var app : Application = Photoshop.app;
var iApp : IApplication = app as IApplication;
2
Let class Application implement IApplication. Then there is no need to cast to IApplication. - mazatwork
As I've noted, it's part of the API, it ain't my class! - George R

2 Answers

0
votes

You should do it with variable that have been defined, not to a class

var t:Application = new Application();
var iApp:IApplication = t as IApplication
0
votes

If the original class doesn't implement the interface, you are out of luck. However; it might be possible to mock the implementation instead (for testing), using for example mockalate (http://mockolate.org/).