| By Andrew Trice | Article Rating: |
|
| February 6, 2007 10:00 AM EST | Reads: |
13,940 |
Object Orientation
Understanding of OOP (object
oriented programming) is fundamental in being successful with the Flex
framework and being able to get the most out of it. People without a
computer science-related (or similar) background may not know much of
the fundamental concepts that comprise OOP and how to apply them
correctly, so here is a quick piece to help you out.
First, object-oriented programming is a programming paradigm where your code is organized into logical objects, and each object has properties and methods. Each object contains similar and/or related functionality, and is organized into classes that logically represent and logically organize its functionality.
For example: Let's say that we have a class "Automobile." This class would contain the information and functions necessary for our application to use the automobile class. We could have a numeric property for the number of wheels, the speed, and the direction (degrees on a compass). This class would also contain methods that control the actions of the Automobile object: accelerate, decelerate(break), turn, start engine, stop engine, etc. Our class would look something like this...
public class Automobile
{
public var speed : Number;
public var direction : Number;
public var numWheels : Number;
public function Automobile()
{ /* constructor */ }
public function accellerate() : void
{ /* speed up the automobile */ }
public function decellerate() : void
{ /* slow down the automobile */ }
public function turn( direction : Number ) : void
{ /* turn the automobile */ }
public function startEngine() : void
{ /* start the automobile engine */ }
public function stopEngine() : void
{ /* stop the automobile engine */ }
}
Ok, now that we have a brief explanation of what object-oriented programming is, we can get into some more aspects of OOP: inheritance and interfaces.
Inheritance is a way to form new objects based on existing objects. When a class inherits from a base class, the new class can utilize public and protected properties and methods from the base class. Inheritance can be used to create different objects that utilize functions within the base class, so that the child classes all utilize the same code base. Inheritance can be used to extend the functionality of existing objects, and inheritance can also be used to override and/or change functionality from the base class.
In ActionScript 3.0, you can access the parent class of your class by using the "super" keyword. For instance, calling the constructor of the parent class would use "super()", where accessing a method of the parent class would use something like: "super.myMethodName()". If a property of the parent class is created with public or protected access, you can access that property in the child class directly by the property name (you would use this.propertyName, not super.propertyName).
Now, let's take our automobile example and apply it to inheritance. We already have a base Automobile class that covers the basic functionality. We can create child classes that extend the functionality of the automobile.
public class SportsCar extends Automobile
{
public function SportsCar()
{
super();
}
override public function accellerate():void
{
/* we can override the accellerate function
so that it accellerates faster than the base
Automobile */
}
}
public class Truck extends Automobile
{
public function Truck()
{
super();
}
public function tow() : void
{
/* we can add a tow function that
allows the Automobile class to tow
items. */
}
}
Published February 6, 2007 Reads 13,940
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Andrew Trice
Andrew Trice is a consultant with Cynergy Systems in Washington, DC, where he specializes in development of Flex-based Rich Internet Applications. Andrew has over 5 years of proven experience in the RIA industry, including application design and development using Flex, Flash, ColdFusion, J2EE and .NET architectures.
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe Fiddles with its Web Apps
- Adobe & Salesforce Cut Cloud Deal
- Hosting.com Launches ColdFusion 9 in the Cloud
- The Real Time Infrastructure Ultimatum
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF






















