How to make this OOP?

BlitzMax Forums/BlitzMax Programming/How to make this OOP?

1) As Globals, and they stay as static to that Type, that mean that even if you made 20 instances of that type, there would only be one of each global
2) No, they stay as functions of the type

What you have is Variables and Procedures of either the type/class itself or instances/objects of that type

Globals and Functions defined within the type are part of the type, but the dont belong to any instance of it, really you can look at them as simply haveing a longer name than before
AType.GlobalVariable  AType.Function:Int() etc
Fields and Methods on the other hand belong to a specific instance of that Type, specificly when in Methods the type "Self"

As an example, if I want to create a new Instance of MyType, I could do this
MyInstance:MyType = New MyType
MyInstance.MethodAllocate(Parameters)
or
MyInstance:MyType = New MyType
MyType.FunctionAllocate(MyInstance,Parameters)
The first one calls the allocate Method inside MyType. This method knows that is was called by MyInstance, and infact thinks of itself as part of MyInstance and reffers to it as "Self"

The second example the allocate is a member of MyType, but you can see that it isnt called by the instance, but rarther by the Type itself, (Self still works, but Mark has said that it really makes no sence in a function in a type, and is really only there for lazy typers with intellisence in the IDE), and MyInstance needs to be passed as a parameter.

The way I do this allocation (for example) is
MyInstance:MyType = MyType.FunctionCreate(Parameters)
The function then News the Instance and passes the Parameters to the Allocate Method.
(I do this for a few reasons, partly becasue it make inheritance easier, but mostly because I dont like NEW as a command in "open" code)

I do agree with Gab, for whilst I would put it all inside a type, that would only be because in my mind it is tidyer, not because Im makeing in any real sence an "Object" in the OOP meaning. All I'd really be doing is creating a subProgram/namespace that contained all the variables and fucntions, then I would just call it as though each function was still a normal function, but now with a longer name.