10.12.2012 Views

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

ActionScript 3.0 Design Patterns.pdf - VideoTutorials-bg.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Even though both of the solutions are workable, they may lack the flexibility and<br />

reusability desired in good design patterns. We need to look further.<br />

The Symmetric Proxy Pattern<br />

The Symmetric Proxy pattern is as much a discovery as an invention. Heliotis and<br />

Schreiner found that they could establish instances of two player objects arranged as<br />

peers over the Internet. Each side has both a proxy and a “real” player. Likewise, the<br />

referees on each side have the same information. Whatever move a player makes is<br />

treated the same by each of the referees. The referee object has no idea where a move<br />

<strong>com</strong>es from—it’s clueless, as Heliotis and Schreiner note. All that the referee has to<br />

do is to call the players when the game is over and let them know the out<strong>com</strong>e. The<br />

referees are perfectly synchronized because they’re reacting to the same state information,<br />

without caring whether the information is local or from a proxy; as a result,<br />

when the game-over conditions are met, both inform the players in exactly the same<br />

way, resetting all variables, and preparing for the next game.<br />

Figure 13-3 shows the object diagram of the Symmetric Proxy Pattern:<br />

Referee 1<br />

Player 1 Proxy 2<br />

Figure 13-3. Symmetric Proxy object diagram<br />

Internet<br />

Proxy 1 Player 2<br />

Referee 2<br />

Keeping in mind that Figure 13-3 is an object diagram and not a class diagram, we<br />

can clearly see that the Symmetric Proxy pattern has each player’s proxy in the opposition’s<br />

camp, so to speak. The referees are treating each side of the Symmetric Proxy<br />

as a <strong>com</strong>plete game. The referee simply takes the moves, evaluates them as being<br />

from one side or the other, and makes game decisions as though only a single host is<br />

in use. In other words, the proxies are treated as the <strong>com</strong>puter playing the live<br />

player, or two live players taking turns on the same keyboard.<br />

The Symmetric Proxy Pattern | 473

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!