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?
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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.
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.