Think of a "Class" as a series of subroutines and functions that build a
car
(kinda like a dll). The Functions return values for the characteristics
(or
"adjectives") that describe the car (e.g. color, trim, interior). These
are
called properties.
The subroutines cause the car to do certain things (Speed up, slow down,
stop). These are called methods.
Once you write the code, to slow down, for example:
Sub Slow_down(mph)
do until car.speed = mph
apply brakes 'Which may be another "method"
loop
end sub
Re-usable code!
I understand that and have done it many times.
Especially when programming for the Spectrum, where you've only got 48K of
memory to play with.
Put the code in a sub and call it from wherever it's needed, passing any
desired data to it.
You never have to write this code again. Instead, you can simply invoke
the
"Slow_down" method of the car class and pass it the desired speed.
Had I created a "Property" named "Speed" for the car, I could have set the
"property" with setProperty to the lower speed:
Function speed(mph)
set property car.speed = mph
end function
Got that.
Now I can create any number of cars (objects) with any number of
characteristics, and have them do any number of things, just by calling
the
Dll (called "instantiating" or "creating an instance of") and passing in
the
specific Function (setting the properties) or Subroutine (invoking the
methods) parameters rather than writing the code whatever number of times.
Sort of got that. Still not quite sunk in. I'll ponder a little longer on
that.
Clearly an "oversimplification" but, pretty much the basics of OOP.
Program
the "object" car by setting its properties and invoking its methods,
rather
than programming the computer to do these things
Now that's the bit that I never got before.
Mainly because it goes against all my programming experience.
It's a little clearer now, but not fully there yet.
As one of us "old timers" surely you remember writing the BASIC code to
create a string of "-"s to form a line across the screen to create a
display
box. Then counting pixels and spaces to fill the box with text. Well, now,
we
only need to set the properties of the TextBox object and all that code
"happens" because somebody created a TextBox class of object..
I've done that in Assembly Language.
Write a sub that accepts all the required parameters to display a textbox or
whatever.
Call it from elsewhere in the code, passing the parameters to the sub, and
the textbox or whatever appears on screen.
I never thought of it as OOP before.
Come to think of it, I've done it in Excel VBA.
I wrote a sub to show my own MsgBox so that I could have different colours,
font sizes, etc.
Call MyMsgSub ("Message","Title", Integer Variable)
The Integer Variable defines the appearance of the MsgBox.
If that's OOP, its easy.
I still don't fully understand the concept, though.
I'm probably more practical than theoretical in this sort of thing.
Quite often I find that I know *how* to make it work, but not *why* it
works.
A little clearer, thanks.
Still not fully confident that I understand.
Thanks for your time.
Henry
<SNIP>