Object Oriented Programming

From Director Online Wiki
Jump to: navigation, search

OOP in general

The idea behind OOP is that you try to separate code-elements from another, so that you can treat them separately without caring about the other. You can compare it to the idea of a microwave - you have an interface to control the microwave, and you get your hot meal from it. You don't need to care how it exactly works - and you can't (or at least shouldn't) change the internal electronics. In code you create such elements, that have certain access-interfaces - so that you can use them without breaking the internal code. These code elements are mostly called classes - or in Director "parentScripts" and "behaviours".

Good sources for deeper information:

[[1]] [[2]]

Basic OOP in Director

Director kind of pushes you to use the basics of OOP, because sprites are controlled by behaviours. These are scripts that should only control the sprite they are attached to. Don't use one movieScript for all your code.

Also try to put recurring tasks into methods. This way you only need to change one method instead of searching though all your code for changes. Give your Methods descriptive names (verbs) that exactly tell what they are supposed to do.

Advanced OOP in Director

Keep in mind that the Directors' Scripting Languages are not fully fledged OOP languages. You may miss things like PrivateVariables and PrivateMethods.

You can use Single Inheritance: define ancestors for your scripts, so they inherit the properties and methods of their ancestor. (See Lingo Inheritance for details - don't trust the Director Documentation there).

Multiple Inheritance is not officially supported.