what would be the "good"OOP-way?

BlitzMax Forums/BlitzMax Beginners Area/what would be the "good"OOP-way?

Abomination(Posted 2006) [#1]
I'm trying to port my GUI from BB3d TO BMAx. (Boy, do I miss those ImageBuffers...)
Now, I'm attempting to do this in an OOP-friendly way. As I'm not accustomed to OOP, i find it hard to figure out where to put the globals, locals, constants and such.
For instance:
I have a MainType to hold functions like update(), MouseUpdate() and Render().
Also there is a GadgetType to hold position, size and color of the gadgets.
Now where should I keep globals like the array thad holds the z-position of the gadgets; or MouseX and MouseY that hold the relative mouse-positions?
There only needs to be one set of these variables so I tend to make them just global. But I could also put them in MainType.
But it seems a bit wierd to refer to them in a Gedgetmethod as MainType.Mousex in stead of just MouseX.
Please give me some guidance.


H&K(Posted 2006) [#2]
A good OOP way is just to hand the user an inteface isnt it?
Is it I as the user who am faced with MyMainType.MouseX, or you as the writter.

Anything that is only used by a type, put it in that type. Equally anything that only uses the type, put it in the type.

I personaly like MyMainType.Mouse.CoorX, but ha, I put everything in a types, and inherit like mad. (I have made a type just to deal with a pair of int screen sizes. Ok so it can deal with any pair of ints. But I only use it for screen sizes)


Abomination(Posted 2006) [#3]
thx H&K
So if the user has to be able to handle a variable, such as an event or a mouseposition I don't put it in a type?
Then how about a variable like the z-order, that is used by almost every type, but has no meaning for the user?


H&K(Posted 2006) [#4]
Well I think on the contary, you make EVERYTHING the user has to deal with part of a type.
And hide Z from the user. (Protected etc)
PDF oop guide to Bmax
I cannot remember who wrote this. But its usefull

See your users are going to be other programmers. So... how would you like your GUI presented to you.

Edit: John J Wrote it. :)


CS_TBL(Posted 2006) [#5]
Isn't inheriting overrated, or at least a firmly debated topic? I never inherit and I'm perfectly happy..


H&K(Posted 2006) [#6]
CS_TBL,

It definetly adds an overhead. But no, I dont think its overrated. (I think I use it too much ATM, and thats stupid:- I delibretly break working types just so that I can inherrit). However there are times when inheriting is very useful.

For example how useful is it that all your types already inheret from "Object"?

The main reason I like Inhereting atm, is the "IS A" rather than "Contains A" mentality
Ive been able to do a "Contains A" thing since Amega Basic which had been an improvment over sinclair Basic (HiSoft), were I couldnt, and its nice to rethink problems with a "IS A" option. ATM Im like a kid in a sweet shop.


CS_TBL(Posted 2006) [#7]
ehrm.. care to spit out a small (no giant masses o' code) demonstrative example on that 'Is a' vs 'Contains a' thing? :P


Abomination(Posted 2006) [#8]
So... how would you like your GUI presented to you
Well... I don't like OOP.
So if I did it "just" for myself I would make all my variables Global( in a huge list :) ).
But when I mentioned this in an other topic, people adviced me to be more OOP-orientated.
So it's more how "others" would like a GUI to be presented to them.
I would still like to know where to put that Z though.


CS_TBL(Posted 2006) [#9]
Making all vars global is the worst idea in the history of bad ideas :P </JP:The Lost World>

Whether you inherit or not is a debate on its own, but by all means: stuff all your vars related to a certain thing into a type of that thing, and avoid globals at any costs!


H&K(Posted 2006) [#10]
The Z buffer should be a global field of the most base type that uses the z buffer. And every object/type that is going to use/be-in the z buffer should inherit from that type.

NB:, If an object uses the z buffer there will be otherthings it has in common with all the other things that use the z buffer. And they should be in this base type as well

NB2:
The entire purpose of OOP is to allow you take your mind off the inner
working of your program (the parts you already completed), and lets you focus on more high-level tasks, as you
continue to create your program.
From John J

If the user doesnt need to know about the Z-Buffer then it should be "Private" :- but my understanding is that Private works differently than it does in other things. But that might just be a different implimentaion, rather than different use


Abomination(Posted 2006) [#11]
the worst idea in the history of bad ideas
Is that a compliment? You coaxer You! hehe.
No, I realy try to better myself...
@H&K
What is a global field?
Type MyType
field Z
end type

or

Type MyType
global Z
end Type
????

But if I create objects of this type or types that inherit this, wont I create multiples of Z instead of just one?
(trying to force my brain back in between my ears)


H&K(Posted 2006) [#12]
type AType
global Z
EndType
Ok, no matter how many Atypes you make, or how many inherited types you make there is only ONE Z

Z is part of the Type, not part of an instance of that type.

Functions within types, also belong just to that type.

The difference between methods and functions within types, is the same as the difference between Fields and Globals


Abomination(Posted 2006) [#13]
AHAAAA! Now that clears up my mind. (as well as my nostrils)
I feel like I'm gently floating over the bitplanes of my amiga-youth.
Meaning: I think I start to understand some simple concept.
I will hush and rush to rewrite all to make use of this.

thanks