Member variables in a Type
BlitzMax Forums/BlitzMax Beginners Area/Member variables in a Type
| ||
I have a question. With the OO capabilities of Types in BlitzMax, I'm trying to find an equivalent to member variables. For example, I want to have some variables in my Type that are not exposed to the outide and are not Global. If I try to use the word Local to define them, I get an error. If I use Global, then each time I reference that variable in different instances of the Type object, it changes the value for all instances. I know Fields will work for the time being, however I don't want to expose those variables to the outside in any way. Any thoughts? |
| ||
Fields is your only option for now. |
| ||
OK. Thanks for the quick response. I had a feeling you would say that. :) |
| ||
there is no type export restriction ( hopefully only yet ) you can only export the whole type to outside ( the module ) using public ( standard ) or hide it for outside the module using private ... |
| ||
I don't follow. When you refernce an attribute in an instance of the type, it is only for that instance. It is not global. Please clarifyType sandwich Field meat:String Field Cheese:String End Type BLT:sandwich = New sandwich BLT.meat = "Bacon" BLT.Cheese = "Cheddar" Turkey:Sandwich = New sandwich Turkey.meat = "Turkey" Turkey.Cheese = "Swiss" Print BLT.meat Print Turkey.meat |
| ||
what he want is to make the field private so only the type instance can access it but not you or any other user that has an instace of this type. This way important data can not be changed from outside in a way that is not allowed. VERY IMPORTANT for real OO Systemdesign! |
| ||
Oh, OK. need to read some more OOP dogma. |
| ||
Dreamora hit it exactly on the head. I was really surprised that this feature hadn't made it in yet. But that is exactly the question I was asking. It's very common in OO dogma to want to make calling routines to go through a method to change internal data for the Class/Type. This way you can enforce data integrity. |
| ||
Is there really no way to create private member vars? That is a pretty big oversight. While spelunking through the module source I did see "private" and "public" but it appears they are only used to expose functions and can't be included in a type declaration. Surely we must be missing something as this is fundamental. BTW, I am impressed so far! |
| ||
No it is not in, was mentioned by mark that private / public are only for module export deklarations ( types / functions / variable declarations ) |