Fx{r} is trying to start the Fx{r} Community! Please join our group on Adobe Groups following this link: http://groups.adobe.com/groups/ab29539ab9.
Fx{r} is now on Twitter too. Follow us @ twitter.com/fx_r!
«
»

ActionScript, Flex 2, Flex resources

variables – public/protected/private/internal/static

Virgil Cristea | 07.01.08 | 10 Comments

Google Buzz

One of the first questions any beginner in OOP and Flex will ask is: What do those public/protected stuff really mean?

Well here is a short table to describe them.

As you should know by now a flex application can be structured in packages. Imagine an application as a cupboard, and it is composed of shelves (packages). In each shelf you have some boxes (classes). Now inside this boxes (classes) you have some small post-its (variables).

Now if you want your post-it data to be available from the box (class) it is in then you need to declare that post-it (variable) as private.

Imagine now that you have a post-it (variable) that contains something that is required in 2 or more boxes (classes) from the same shelf. In that case you need to declare your post-it (variable) as internal.

Another common case is when you want your post-it to be available to all other boxes no matter where they reside in the cupboard. You need to declare it public.

In your programs you will want to extend the boxes at some point (class inheritance). If you want a post-it (variable) to be available to the box it resides in (declared in) and also all the other boxes that are based on this one (the base box is for example: Documents and it can be extended to Music Documents and Pictures Documents) you need to declare it as internal.

So if we list the variables from their restrictive access level to the most general the list would be:

Code placement Private Internal Protected Public
Same class Allow Allow Allow Allow
Descendants of class Deny Allow Allow Allow
Classes in same package Deny Allow Deny Allow
Other package Deny Deny Deny Allow

A different keyword is const. It can be applied to any post-it (variable). If you apply it that will mean that you cannot change the value that is kept in that post-it (variable). In fact the value there is set in code at the develop time (like the name of the program/cupboard) and cannot be changed later.

Share and Enjoy:
  • Twitter
  • Google Buzz
  • LinkedIn
  • Google Bookmarks
  • del.icio.us
  • Digg
  • Sphinn
  • blogmarks
  • Reddit
  • StumbleUpon
  • Facebook
  • DZone
  • FriendFeed
  • Yahoo! Buzz
  • Yahoo! Bookmarks
  • Slashdot
  • MySpace
  • Add to favorites




Tags: , , , , , , ,

This post was written by Virgil Cristea

Views: 8491

related

10 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

:

:


«
»