signals with VOs vs. injecting models

2 views
Skip to first unread message

John Lindquist

unread,
Jan 15, 2010, 4:52:31 PM1/15/10
to as3-signals
My question comes from browsing alec's Pong source here (this class
specifically):

http://github.com/alecmce/RobotLegsPong/blob/master/src/app/view/mediator/ScoreBoardMediator.as

You'll notice in this Mediator that the model (ScoreModel) is injected
and anytime the "change" signal is fired, it just reassigns the value
from the injected model. Now, this could have been achieved just as
easily by sending a ScoreVO along with the signal...

Does anyone have an argument why one approach is better than the
other? Or is it just preference? (I like the injected model approach
myself...)

Robert Penner

unread,
Jan 15, 2010, 5:13:38 PM1/15/10
to as3-s...@googlegroups.com
There's no obvious winner between the approaches so it's preference.

For sake of discussion, the other approach would be to specify that
the "changed" Signal sends uints for the left and right score:

// ScoreModel.as

public function ScoreModel()
{
_currentLeftScore = 0;
_currentRightScore = 0;
_changed = new Signal(uint, uint);
}

// ScoreBoardMediator.as

private function onScoreChanged(currentLeftScore:uint,
currentRightScore:uint):void
...

I want to highlight the fact that you can send multiple objects
through a Signal without having to wrap them in a value object class.

Robert

John Lindquist

unread,
Jan 15, 2010, 5:27:06 PM1/15/10
to as3-s...@googlegroups.com
So, at that point, if you're stuck on strong typing you're better off just ditching VOs altogether and making your custom SignalO's :)

Robert Penner

unread,
Jan 15, 2010, 6:52:42 PM1/15/10
to as3-s...@googlegroups.com
Right, since we have a Score we should probably send that instead of
the two uints:

// ScoreModel

_changed = new Signal(Score);

...

public function incrementRightScore():void
{
_currentRightScore++;
_changed.dispatch(this);

Reply all
Reply to author
Forward
0 new messages