Member variables in a Type

BlitzMax Forums/BlitzMax Beginners Area/Member variables in a Type

Cartman(Posted 2005) [#1]
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?


Beaker(Posted 2005) [#2]
Fields is your only option for now.


Cartman(Posted 2005) [#3]
OK. Thanks for the quick response. I had a feeling you would say that. :)


Dreamora(Posted 2005) [#4]
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 ...


bradford6(Posted 2005) [#5]
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 clarify

Type 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



Dreamora(Posted 2005) [#6]
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!


bradford6(Posted 2005) [#7]
Oh, OK. need to read some more OOP dogma.


Cartman(Posted 2005) [#8]
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.


Shaun Sullivan(Posted 2005) [#9]
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!


Dreamora(Posted 2005) [#10]
No it is not in, was mentioned by mark that private / public are only for module export deklarations ( types / functions / variable declarations )