Beginning ActionScript 3.0 –Summary of OOP

Myspace-256x256 Ok, we have finished our small discussion about the big topic, OOP. Our discussion here is just want to give you some basic ideas about OOP. For more details you need to read some other books.

Let’s do some reviews.

What is OOP, what‘s the difference between object-oriented programming and procedure-oriented programming?

Can you answer now? Remember each programming methodology has its own place. Different projects need different solutions. So, find a suitable way. OOP is suitable for big project, if you’re writing a small application; maybe you don’t need it, because OOP will bring many extrinsic complexities. Not everything needs to be in the OO way.

If you need the OOP way, please remember how to define the class. In our example, we all use the default package, but it’s an important way to organize your code with the package. So, forgive me that I haven’t introduced it to you, well, I think you don’t need it now, and when you need it; you’ll find it.

For the modifiers of the class, the most common is “public”, which means visible to references everywhere. The default one is “internal”, which refers to visible to references inside the current package.

And there still two modifiers you may not familiar with. The first one is “dynamic”, which use to define dynamic class, it allow properties to be added to instances at run time. The second one is the “final”, when you want to define a class that you don’t want others to be inherited from, then you should use the keyword “final” to modify it.

For the modifier to the class members, we discuss the “public”, “internal”, “private” and so on. Take a look at the following list if you forget the meanings of them.

internal (default) Visible to references inside the same package.

private Visible to references in the same class.

protected Visible to references in the same class and derived classes.

public Visible to references everywhere.

static Specifies that a property belongs to the class, as opposed to instances of the class.

UserDefinedNamespace Custom namespace name defined by user.

Here, we don’t talk about the UserDefinedNamespace, because I think it’s not suitable for the beginners.

If you need to describe the “is a” relationship, then you need the inheritance. Inheritance is a form of code reuse that allows programmers to develop new classes that are based on existing classes. The existing classes are often referred to as base classes or superclasses, while the new classes are usually called subclasses.

Except the inheritance, we also discuss the interface. An interface is a collection of method declarations that allows unrelated objects to communicate with one another. Interface describe the relationship of “like a”.

Public class AlarmDoor extends Door implements IAlarm.

This example tells the difference between the inheritance and interface.

We also introduce the override mechanism.

override public function get classDescription():String{
return cookDescription;

And discuss the overload.

var a:int = 1+1;
var b:String = “1″+”1″;

Remember, overload happens in one class, while override needs two or more classes, because override needs inheritance.

The polymorphism,

var person:Person = _______________

Polymorphism allows the programmer to treat derived class members just like their parent class’ members. More precisely, Polymorphism in object-oriented programming is the ability of objects belonging to different data types to respond to method calls of methods of the same name, each one according to an appropriate type-specific behavior.

When you deal with the polymorphism, you may need three operators,”as”, “instanceof” and “is”. Here, “instanceof” has the same function with “is” operator. And the “instanceof” operator is deprecated; you can use the “is” operator instead.

For the “is” and “as” operator, one is use for check the type, it returns a Boolean value, the other is use for type conversion. I think you should find out the usage of these two operators yourselfJ

For OOP, there’re some guidelines, such as SRP, OCP, LSP and so on. I hope you can find the exactly meaning of each guideline. And some books, such as <Head First Object Oriented Analysis and Design>, and the <Design Patterns> by GoF, will be helpful for you to clarify some basic ideas and build a system concept about OOP.

Share and Enjoy:
  • Digg
  • Facebook
  • Google Bookmarks
  • DZone
  • Reddit
  • Technorati
  • StumbleUpon
  • Twitter
RSS Enjoy this Post? Subscribe to

RSS Feed   RSS Feed     Email Feed  Email Feed Follow us Follow us
You can leave a response, or trackback from your own site.

Leave a Reply