Some great thoughts, thank you! Here's some more...

by (no login)

Firstly, I should confess that I do not usually use object orientated code in my programming. However, I have written enough programs to realise when OOP would have been a good thing to use.

What I think OOP is all about:
i) Creating small blocks of code (objects) which perform specific functions and joining them together (inheritance) to create larger objects.
ii) Providing security and stability so that provided the objects have been coded properly in the first place (they sometimes aren't!) they cannot be compromised.

How might inheritance work in QB64?

TYPE col
r AS SINGLE
g AS SINGLE
b AS SINGLE
FUNCTION greyscalevalue
greyscalevalue=(col.r+col.g+col.b)/3
END FUNCTION
END TYPE

TYPE pal
c(0 TO 255) AS col
SUB brighten (change AS SIGNLE)
FOR i=0 TO 255
c(i).r=c(i).r+1
c(i).g=c(i).g+1
c(i).b=c(i).b+1
NEXT
END SUB
FUNCTION averagegreyvalue
FOR i=0 TO 255
v=v+c(i).greyscalevalue
NEXT
averagegreyvalue=v/256
END FUNCTION
END TYPE

DIM mypalette AS pal
mypalette.brighten 2.5
PRINT mypalette.c(5).r
PRINT mypalette.c(255).greyscalevalue
PRINT mypalette.averagegreyvalue

RE: Criticism of the use of the word TYPE instead of calling it a CLASS or an OBJECT.
When I look at the above code from a QBASIC programmer's point of view it makes sense. There is a TYPE with some functions and subs which do things with the data in the type. If I called it a CLASS or OBJECT, would that really make it any easier for a BASIC programmer with no experience of OOP to understand? Sure, you sometimes might have an object that is just a collection of subs and functions with no variables in its structure, but this is a less likely case.

RE: The suggestion that the proposed OOP method is flawed.
I'm willing to learn, but I need more concrete examples of why it is flawed, and how it could/should be done.

PS: C++ inheritance is a complete nightmare for me, I've read the books, I've seen the examples and at the end of the day there are simply too many ways of calling the sky blue.

PPS: RE: HANDLES
I wanted to add a little point about handles, which at first seem totally different to OOP. Handles were invented so that access to certain data and functionality could be managed/controlled. OOP can achieve exactly the same thing, but better because you can allow direct access to selected variables.

Posted on Apr 18, 2008, 6:24 AM
from IP address 220.235.109.87

Respond to this message   

Return to Index


Response TitleAuthor and Date
About your example. on Apr 18
 In other words, you want something like the C++ scope operator.rpgfan3233 on Apr 18
Re: C++ inheritance is a complete nightmare for merpgfan3233 on Apr 18
 * They're the QBASIC colors LOLqbguy on Apr 18