Skip to content

Instantly share code, notes, and snippets.

@cambiata
Last active December 18, 2015 12:19
Show Gist options
  • Save cambiata/5781850 to your computer and use it in GitHub Desktop.
Save cambiata/5781850 to your computer and use it in GitHub Desktop.
HaxeDCI Greeting example - https://github.com/ciscoheat/haxedci
package ;
import neko.Lib;
import dci.Context;
/**
* ...
* @author
*/
class Main
{
static function main()
{
new Greeting({name:"Anna"}, "Hello", {name:"World"}).greet();
}
}
typedef ISomeone = {
name: String,
};
typedef IMessage = String;
@:build(Dci.role(Greeting))
private abstract Someone(ISomeone)
{
public function name()
{
return this.name;
}
}
@:build(Dci.role(Greeting))
private abstract Message(IMessage)
{}
class Greeting implements Context
{
@role var sender: Someone;
@role var message: Message;
@role var recipient: Someone;
public function new (sender:ISomeone, message:IMessage, recipient:ISomeone)
{
this.sender = new Someone(sender);
this.message = new Message(message);
this.recipient = new Someone(recipient);
}
public function greet()
{
trace('${sender.name()} says: "$message, ${recipient.name()}!".');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment