Abstract Data Types
       by kirupa  |  4 January 2006

When you write code in Flash, you launch the Actions panel and start writing your statements. You don't think about how the Actions panel retrieves the data, how Flash compiles your code into an SWF, or how memory is managed internally by the Flash application. Such information is not directly relevant to whatever program you are writing. But, wouldn't your task be more complicated if you did have to figure out how all of those pieces worked in order to code in Flash?

Hiding those unnecessary details is known by a scary term - abstraction. The idea is that you can simply box up certain features/code/etc. and hope nobody would need to open up the box and look at the messy insides. As long as you plug in the right data to the box, you would received a predicted output.

Abstract Data Types (ADT's) work similarly. They are sections of code that exist somewhere created by somebody else, but they help you save time and not worry about messy programming details. You probably have used ADT's without even knowing it, for example, the String data type.

The String data type comes built-in with Flash, and it allows for you to use and manipulate text-based data. When using a String object, you really do not think too much about how the String class is defined, how the various properties work, or how the data is stored internally. You only need a basic understanding of the String's methods in order to use it:

[ the foo object, because it is a String, allows you to access the String's methods ]

Whoever wrote the String class took care of the details so you do not have to worry about them. Because of the String data type, you can spend more time working with text as opposed to fiddling with the underlying String representation.

In this tutorial, you will learn about user defined data types - or commonly known as abstract data types by deconstructing a Graph ADT. You will learn how to create a good ADT and learn how the Graph ADT was approached and coded.

Path Finding Example
The following is an animation I created using the Graph ADT. Instructions on how to use it are below the animation:

[ an example created using the Graph ADT ]

Graph Example - Instructions

Click on any two squares to find a path between them. Since only two nodes can be selected at any given time, make sure to unselect a node by clicking on a selected node again.

Now that you have an idea of something cool that can be created with our ADT, let's learn about creating an ADT!

Creating an ADT
The following guidelines help you in creating a good, usable ADT:

  1. Plan Ahead
    Your ADT will be a very important part of your program. You will save time in the long-run if you brainstorm some operations, features, and potential troubles you may run into before beginning to code.

  2. Keep it Simple
    An ADT should make life easier for you as a programmer. When creating your ADT, keep the operations you can perform on an object simple, straightforward, and consistent.

  3. Be Concise
    Your operations should be relevant to the ADT's purpose. Remember, your ADT is not your main program. It is merely an accessory that you use to build your main program.

  4. Be Comprehensive
    After step 2, it seems odd to mention this, but ensure that any relevant information can be easily retrieved via your ADT itself. For example, any set operation has a complementary get operation.

  5. Do not Mix and Match
    Your ADT may be very generic (such as a graph, list, etc.) or it may be very domain-specific (such as an address book). It is good practice to avoid mixing and matching generic and domain-specific types, for it will make it difficult to manage your code and find/fix type incompatibilities in the long-run.

In the next page, I will explain how I approached the Graph ADT.

Onwards to the next page!

1 | 2 | 3 | 4 | 5


kirupa.com's fast and reliable hosting provided by Media Temple.