Are you working on something right now that makes use of interfaces? Copy and paste an interface into the comments of this post (no need for code tags or anything)....
Actionscript:
-
package app{
-
-
import flash.events.IEventDispatcher;
-
-
public interface IBaseModel extends IEventDispatcher{
-
-
function set decimal(val:int):void;
-
-
function get decimal():int ;
-
-
function get stringValue():String;
-
-
function get errorMessage():String;
-
-
function set base(val:int):void;
-
-
function get base():int;
-
-
function startCounting(interval:Number, changeBy:Number):void;
-
-
function stopCounting():void;
-
}
-
}
14 Comments
package bk.gallery.display {
public interface IGalleryItem {
function set props(props:Object) : void;
function get props() : Object;
function load() : void;
function transitionIn() : void;
function onTransitionInComplete() : void;
function transitionOut() : void;
function onTransitionOutComplete() : void;
}
}
nice one ben…. I’m also working on something with an interface that has:
transitionIn(), transitionOut() functions… huge timesaver especially if your using them with template method pattern so that your “abstract” class is doing any redundant work and your subclasses can focus on the different implementations for the transitions…
package com.hapticdata.features.interfaces
{
import flash.display.Stage;
import com.hapticdata.features.ColorPalette;
/**
* An interface to describe the necessary functionalities / communications between a feature and a controller
* @author kphillips
*/
public interface IFeature
{
function build(colors:ColorPalette,xmlSrc:String):void;
function hide(transition:Boolean=true,callback:Function=null):void;
function show(transition:Boolean=true,callback:Function=null):void;
function get isHidden():Boolean;
function kill():void;
//an array of user-interaction instances, such as buttons
function get interfaceOutlets():Array;
}
}
I’m using this to loosely communicate between a master controller and separate .swf’s of different views.
@kyle: Nice. It’s interesting how much can be inferred just from looking at an interface
package ext {
import flash.display.DisplayObject;
public interface ITextureMaterial {
function setTexture (t:DisplayObject):void;
}
}
it was “set texture” originally but changed later because if type conflict.
package as3ui.framework.component
{
import as3ui.framework.IDisplayObject;
public interface IBasicComponent extends IDisplayObject
{
function get componentInfo():BasicComponentInfo;
function setData(data:Object):void;
function show():void;
function hide():void;
function dispose():void;
}
}
package com.imarkahann.iagi.controls{
import com.imarkahann.iagi.core.IGIDisplayObject;
public interface IProgressBar extends IGIDisplayObject
{
function setProgress(nProgress:Number) : void
}
}
//No need to lot of comments. It is just use to create progressbars in external swf
package com.nikitadudnik.minivideoplayer.model
{
import com.nikitadudnik.minivideoplayer.events.ICommand;
import com.nikitadudnik.minivideoplayer.events.IMetadataHandler;
import flash.media.Video;
import flash.net.NetStream;
/**
* …
* @author Nikita Dudnik
*/
public interface IVideoStreamPlayer extends INetStreamProvider
{
function open(s:String):void;
function close():void;
function pause():void;
function resume():void;
function get opened():Boolean;
function get playing():Boolean;
function get paused():Boolean;
function set stream_started(command:ICommand):void;
function set stream_stopped(command:ICommand):void;
function set metadata_handler(handler:IMetadataHandler):void;
function set stream_not_found(command:ICommand):void;
}
}
I don’t use an interface due to the fact I work mostly with AS2 and non-OOP related environments.
SHUT UP ;_;
Niall, interfaces are still useful without OOP, like in my example it allows treatment of unrelated classes instances as if they were all of the same type. Basically, an interface is just a way to say “I know there is this function(s) in these codes, and it is safe to call it”
@Niall,
The interface concept is very abstract, and i think it is very difficult to understand the real benefit without a concret case. If you like read i advice you this book : http://oreilly.com/catalog/9780596007126 (I have the french version “Design Patterns tête la première”). Examples are coded in Java but all concept are very interesting and wrote with finess and humor
public interface ILoadedContent extends IEventDispatcher
{
function get isInitialized() : Boolean;
/**
* Initializes the object.
*
* Dispatches an AsynchronousContentEvent on completion.
*/
function initialize() : void;
/**
* Destroys the object.
*
* Dispatches an AsynchronousContentEvent on completion.
*/
function destroy() : void;
/**
* Shows the object.
*
* Dispatches an AsynchronousContentEvent on completion.
*/
function show() : void;
/**
* Hides the object.
*
* Dispatches an AsynchronousContentEvent on completion.
*/
function hide() : void;
}
package app{
import flash.events.IEventDispatcher;
public interface IBaseModel extends IEventDispatcher{
function set decimal(val:int):void;
function get decimal():int ;
function get stringValue():String;
function get errorMessage():String;
function set base(val:int):void;
function get base():int;
function startCounting(interval:Number, changeBy:Number):void;
function stopCounting():void;
}
}