Quote:
Originally Posted by Inverness
"Encapsulation describes the ability of an object to hide its data and methods from the rest of the world - one of the fundamental principles of OOP (Object Oriented Programming)."
|
Which is achievable like so
PHP Code:
class CPoly {
int x, y;
public:
void set_vars (int,int);
int getarea () {return (x*y);}
};
With that, only the local object can access x,y and everything else will have to use the two functions to interact with the variables. This is an example of how you hide data/methods in OOP languages. Global functions
do not promote clean OOP programming standards.
Unless Stefan implements protected variables sometime soon (something I actually suggested a while ago), this isn't possible in gscript and global functions don't fall under the encapsulation umbrella.
Encapsulation isn't referring to protecting your code from other coders

. You could achieve the same effect by having a class with private functions and make sure only you can read the class. It's making sure you follow OOP rules and only allow the local class have access to it's variables.
Nothing should ever need access to everything at any point. Classes can be nicely labeled ("mud_functions", "magic_functions"), and new scripters will be able to find what they are looking for alot easier than sifting through a massive Control-NPC script. This also means that an item object can't turn a player into a duck and plants don't spit out weapons. Global functions are just messy and lazy.
And yes, I realize there are hard coded global functions. I was suggesting that you could happily follow the concept of inheritance using classes to achieve the same effect...alot more cleaner as well.