-
Designing an interface for a display object
I'm working on a series of classes that each distort an input image using a series of parameters. Each class is a Sprite that contains the distorted version of the input image.
I have the parameters defined in an interface that I plan to implement in each class. How can I include in the interface the fact that each implementation should extend Sprite?
I suppose that I could use a getter that returns a Sprite, but it would be nice if the classes themselves could be added to the display list.
-
Someone please correct me if I'm wrong - but I don't believe you can implement display objects at the interface level (as there isn't any ISprite or IMovieClip to invoke)...instead just lay out your interface as a standalone, and then have each of your child classes implement the interface and also extend sprite:
public final class Distortion1 extends Sprite implements IDistortion{ ... }
-
Thanks.
That's what I have. The problem is that I end up doing addChild(_distortion as Distortion1) which is less flexible than ideal.
Maybe I'll add function get displayObject()isplayObject to the interface.
-
Perhaps an abstract class is more what you need. You could have a class which extends Sprite which declares the methods you need (or even implements the existing interface you have), but all those methods are simply empty stubs. Then you can extend that class with actual useful subclasses which override the stubs.
-
Yeah, I had considered that too. It seemed sloppier than an interface though, because then you need to override everything.
There are definitely workarounds, but it seems like this ought to be pretty straightforward.
-
I agree, it would be nice if DisplayObject.addChild took an interface rather than DisplayObject, or if there was a way to add extra type information to an interface like you ideally want. Or even a proper "abstract" keyword. Oh well. It's an evolving language.
I think a true abstract class would fit your needs pretty well, but we can only simulate abstracts at the moment.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|