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.

Why Abstractions Are Important<br />

We can see two key reasons that abstractions are important for both OOP and<br />

<strong>Design</strong> <strong>Patterns</strong>. Rather than being dogged by minutiae of the problem, abstraction<br />

helps to focus on what parts, independent of their details, are required to solve the<br />

problem. Does this mean that you ignore the details? Not at all. Rather, the details<br />

are handled by adding them just when they’re needed. For instance, in the example<br />

in the previous section, the exact video file is unimportant. All that’s important is<br />

that some video name (a detail) be provided when we’re ready to play it. We don’t<br />

need to build a theater around a single movie. Likewise, we don’t need to build a<br />

class around a single video file.<br />

The second advantage of abstraction is flexibility. If you’re thinking that in the previous<br />

section the Example 1-2 was easier and took less code and classes, you’re right.<br />

However, suppose you want to place four videos on the stage. Then, all you would<br />

need to do is to create four instances using the abstract class instead of re-writing<br />

three more classes. In other words, the second method using abstraction is more flexible.<br />

In addition to adding more videos instances, we can easily change the video file<br />

we choose to play.<br />

Encapsulation<br />

Encapsulation is what makes a code object an object. If you have a tail, four legs, a<br />

cold nose and a bark, you do not have a dog. You just have a collection of parts that<br />

make up a dog. When you bring all of the doggy parts together, you know that each<br />

part is a part but collectively, you do not think of parts but a reality sui generis. That<br />

is, a dog is an object unto itself and not doggy parts that happen to hang together.<br />

Encapsulation has a similar effect on a collection of operations and properties.<br />

Encapsulation has been used synonymously with other terms such as <strong>com</strong>ponent and<br />

module. In the context of OOP, encapsulation is often called a black box, meaning<br />

you can see it do certain things but you cannot see the inner workings. Actually, a lot<br />

of things we deal with all the time are black boxes, such as our dog. We can see the<br />

dog do a lot of different things, and we can interact with the dog. However, we really<br />

don’t know (or usually care) about how the physiology of the dog works—dogs are<br />

not transparent. They’re black boxes.<br />

The good thing about the concept of a black boxis that we don’t have to worry<br />

about the inner workings or parts. We just have to know how we can deal with it,<br />

secure in the knowledge that whatever makes the black boxwork is fine as long as it<br />

works as we think it should.<br />

Encapsulation | 15

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

Saved successfully!

Ooh no, something went wrong!