ActionScript 3.0 Design Patterns

(Chris Devlin) #1

44 | Chapter 1: Object-Oriented Programming, Design Patterns, and ActionScript 3.0


state here is a bit more contextually rich because it is the key concept around which


the design pattern has been built.


In general, though, when you seestateused, it’s just referring to the current value of


an object’s variables.


Client and Request


In this age of the Internet and Web, the termclientis used to differentiate the


requesting source from theserverfrom which a request is being made. We think of


client/server pairs. Moreover, the termrequestis used to indicate that a Web page


has been called from the server.


In the context of design patterns, instead of a client/server pair, think of aclient/


objectpair. A request is what the client sends to the object to get it to perform an


operation—launch a method. In this context, arequest is the only way to get an object


to execute a method’s operations. The request is the only way to launch an operation


since the object’s internal state cannot be accessed directly because of encapsulation.


Don’t forget Flash Media Server clients and servers! If you work with
Flash Media Server 2, you’re aware of client-side and server-side pro-
grams. You can launch a server-side method with a request from a cli-
ent-side object. However, you can launch a client-side operation with
a client-side request as well and a server-side method with a server-
side request. So if you’re using Flash Media Server 2, you’re just going
to have to keep the concepts separate.

In a nutshell, theclientis the source of arequestto an object’s method. A quick exam-


ple shows exactly what this looks like. Example 1-37 and Example 1-38 make up an


application that does nothing except show a client making a request to an object.


Example 1-37. MyObject.as


package
{
public class MyObject
{
private var fire:String;


public function MyObject( ):void {}
public function worksForRequest( ):void
{
fire="This was requested by a client";
trace(fire);
}
}
}

Free download pdf