Some background info: I’ve been freestyling ActionScript 3 for a while now, and recently decided to pick up a book and learn OOP/Classes like a pro. However, since I’ve always worked out logic as I coded, there are a few concepts in early chapters that I’m not fully grasping.
I’ll start with a simple one:
In examples, variables seemed to be declared private all the time. For example, we have a class position, and xCoord, yCoord are declared privately. To access them we use the public methods getX() and getY(). To me, it seems to be much more intuitive just having xCoord and yCoord declared publicly and accessing them directly. Perhaps I’m missing the bigger picture? Is there a telling example when indeed, it’s far more advantageous to use methods to get values of private variables rather than declaring the variables publicly in the first place?
Thanks guys. I hope to be enlightened soon.