Archive

Posts Tagged ‘functional’

AS3 – Object Oriented Programming – Intro

April 16th, 2009

Programmers who are not-familiar with Object Oriented Programming, find it hard to understand and cope with the concepts of object oriented programming. And moving from function oriented programming to object oriented programming can be a real pain.
That’s because they don’t have the right thinking. They think, “hmm, so I have this instance of this class and i must call this function on this object; for that I must use the . (dot) operator…”.
Actually OOP tries to resemble nature. That’s right, nature proved us it’s way for millions of years, why not take after it?… or something like this :-)

Let’s look at a nature example:
We have this big, beautiful apple. We look at it and we think “all apples look roughly the same”. So we take our apple, we look even closer to it and realize that even though it looks like all the other apples, there’s something particular about it: it’s a “Golden Delicious” apple. Now we know 2 things about it: it’s an apple, and furthermore it’s a Golden Delicious apple. We realize now that we can separate all the “Golden Delicious” apples from other classes of apples.
So here we are now:
We have the Apples class, which contains the Golden Delicious class and all the other apple classes: like Ultra Red Gala, Cameo, etc.
Furthermore, we can say: “but all the apples are fruits!”. Which is true.
This creates the next hierarchy:

  • Fruit
    • Apple
      • Golden Delicious
      • Ultra Red Gala
      • Cameo

Ok we know something about classes, but what is our apple? It’s not a class, it can’t be a class because it’s an object. That’s right: the class of our apple is “Golden Delicious”, the base class is “Apple”, but our apple is an instance of the class “Golden Delicious”.

Ok, that’s a very simplistic way of looking at Object Oriented programming.
This is only an introduction, as OOP is very complex, OOP in AS3 is complex too, so i’ll try to explain everything that’s needed to find your way into OO programming world.

I think it’s worth mentioning here that OOP concepts are common on all OO programming languages, however the syntax and features may differ from language to language.

Follow on to the first actual part of this tutorial: AS3 – Object Oriented Programming – Part1

Object Oriented Programming , , , ,