Link to home
Start Free TrialLog in
Avatar of gotaquestion
gotaquestion

asked on

in as3 - public static variables make life easy so what's the problem?

I have many classes spread across many .as files under one package.
for example:

MyClass1.as
package MyPackage{
public class MyClass1{
public static var MyVariable:String
}
}

MyClass2.as
package MyPackage{
import MyPackage.*;
public class MyClass2{
 MyClass1.MyVariable ="Hello";
}
}

I've learned about setters and getters as well but why bother?  Does static take up more memory?  Is the code gonna run slower?  What's the down side?
Avatar of blue-genie
blue-genie
Flag of South Africa image

the premise is that keeping things private when they should be private is better for security reasons and also for preventing things being changed or accessed unintentionally.
if you have 2 classes that you use and they both have a public color variable - confusion could arise later on.
i don't think there is that much difference in terms of memory usage.
ASKER CERTIFIED SOLUTION
Avatar of Jones911
Jones911

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
just out of interest - any object is eligible for garbage collection when there is no reference to it. so your static variables/classes will be gc'd if there no more reference to the object to which it pertains?

Avatar of Jones911
Jones911

But if you create it once and put data in it it will never be out of scope anywhere in your application you can then reference that same item.