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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

context. The subsequent chapters use these terms a good deal, and a misunderstanding<br />

at the outset can lead to confusion now and later.<br />

Implementation<br />

For the most part, the term implementation is a noun referring to the details—the<br />

actual code—in a program. So when referring to an implementation, the reference is<br />

to the actual program as it is coded. Implementation is the internal details of a program,<br />

but is often used to refer to a method or class itself.<br />

You may run into some confusion when the keyword implements refers to contracting<br />

with an interface structure. For example, the line:<br />

class MyClass implements IMyInterface<br />

has the effect of passing the interface of IMyInterface to MyClass. To say that MyClass<br />

implements IMyInterface really means that MyClass promises to use all the signatures<br />

of IMyInterface and add the coding details to them. So the phrase MyClass implemented<br />

IMyInterface means that MyClass took all the methods in IMyInterface and<br />

added the code necessary to make them do something while preserving their<br />

signatures.<br />

One of the two main principles of design pattern programming is program to an<br />

interface, not an implementation. However, you must remember that implementation<br />

is employed in different contexts, and its specific meaning depends on these contexts.<br />

Throughout this book, you will see references to implementation used again<br />

and again with different design patterns, and you need to consider the other elements<br />

being discussed where the term is used.<br />

State<br />

The term state is not part of the <strong>ActionScript</strong> <strong>3.0</strong> lexicon (like implements is), but the<br />

term is used in discussing design patterns. Essentially, state is used to refer to an<br />

object’s current condition. For the most part you will see state used to convey the<br />

value of a key variable. Imagine a class with a single method with a Boolean value set<br />

in the method. The Boolean can either be true or false. So its state is either true or<br />

false—which could represent on/off, allow/disallow, or any number of binary conditions.<br />

The exact meaning of true or false depends on the position of the class in<br />

the rest of the design pattern. A more specific example would be an object that plays<br />

and stops an MP3 file. If the MP3 is playing, it’s in a play state, while if it’s not playing,<br />

it’s in a stop state.<br />

One use of state is in the context of a state machine and the State design pattern you<br />

will be seeing in Chapter 10. A state engine is a data structure made up of a state network<br />

where changes in state affect the entire application. The State design pattern is<br />

centered on an object’s behavior changing when its internal state changes. The term<br />

Principles of <strong>Design</strong> Pattern Development | 43

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

Saved successfully!

Ooh no, something went wrong!