What are the best practices on using private
and public
functions in AS3?
If I am unsure as to which it should be, should I always use private
?
This is irrelevant to the language you use, Maybe language-agnostic tag suits for this question. You can find an answer in any object oriented language book.
Ιn a nutshell, you use private when you don't want other objects having access to those functions in contrary with public.
Something that you might see a lot is that private functions usually utilize properties that resides inside the object and there are in the same scope. This happens when the internal process doesn't concern other objects, for good structuring and readability reasons.
public class ExampleClass {
private var message : String;
public function publicMethod(argument:String):String {
argument = "passing argument utilization";
}
private function privateMethod():void {
this.message = "manipulate object attribute";
}
}
Another term that you might want to see is encapsulation, and the bound between private properties and public functions.