09
encapsulation

organization

programming is all about organization. let's review all of the data structures we've covered so far and see how they enable us to organize, by packaging and labeling.

variables

variables let us label values, and then use the label in place of the value.

arrays

arrays allow us to gather multiple values into a single variable that stores the values in order.

functions

functions allow us to gather multiple statements into a single variable and then execute the statements from multiple places without rewriting them.

objects

objects allow us to collect multiple values into a single variable that stores the values by name.

movie clips

movie clips allow us to collect graphics and code into an environment that has a concept of time.

object oriented programming

hopefully you've seen by now that using objects can be very convenient. we don't need to worry much about how things work, just what controls are provided. complexity is encapsulated within the object, and exposed through a simpler interface of properties and methods with explicit datatypes and method signatures.

just as variables become handy as soon as we start using the same value in multiple places, and functions become advantageous as soon as we have a few statements that we'd like to be able to reuse, objects are useful for grouping a set of conceptually related properties and methods, and controlling how they can be accessed and / or modified.

breaking a programming task into a structure of cooperating objects is called object-oriented programming. it is a methodology of organization and little more. but organization is a highly effective tool for addressing complexity. some programming tasks are trivial enough that no extra organization is needed. a simple timeline narrative may only need a few gotoAndPlay() function calls. but bigger projects generally benefit from an object-oriented technique in the following ways:

by being able to define our own objects, we can implement new datatypes to complement and expand on the native types offered by actionscript, while still being able to take advantage of compile-time type checking. we can build complex applications, but if we engineer them from simple, well-defined parts, those parts can be recombined in other ways to build other applications with less effort.