Maybe you like a discussion when to use objects?
For people not knowing what to do with a class..
A class's main feature is being a data container.
Each newly created instance of a class hold's it's own private data.
Put the instances in an array and you'll have a collection with unique data per element.
You can do a similar thing with structures (type variables).
To 'reach' the data container like a string or long variable inside a class a function aka method or property is required.
When a class is newly created a signal is given by calling a Create methoid (if implemented by you)
This way you may set defaults or raise events... whatever.
When the object is unset a Destroy method can be invoked, this way you can delete memory or close files and so on.
Basically this is the functionality of a class.
A black box you let do things, it does not conflict with other instances (like a global variable you ever may have used for some purpose) and runs selfcontained.
The way PB creates classes is com based and therefore directly usable for other languages (in the form of a dll).
So the best things are:
1) Maintains private data per instance.
2) Can clean up it's mess, guaranteed in any case (unless when an application crashes).
3) No need to declare functions.. ordinary declarations are daunting!!
There are much more benefits like multiple references and still being guaranteed of proper clean up but that goes beyond this simple explaination.
What i am a bit afraid of is that class are going to be used for any silly functionality.
An ordinary module can be as equally modular as a class.
Several invokes to functions in a module don't have to interfere with each other.
Modules can not create unique instances holding private data.
It's a global variable or a local function variable, nothing else.
Using classes means, will you hold multiple data blocks?
By using a class you won't need to mess with memory pointers to 'make' unique data fragments using an old fashion module.
That a class can have functions is a secundary (but needed) thing.
Btw, remember a type variable could not have dynamic strings?
A class can hold dynamic strings and can be seen as a special type variable.
For people not knowing what to do with a class..
A class's main feature is being a data container.
Each newly created instance of a class hold's it's own private data.
Put the instances in an array and you'll have a collection with unique data per element.
You can do a similar thing with structures (type variables).
To 'reach' the data container like a string or long variable inside a class a function aka method or property is required.
When a class is newly created a signal is given by calling a Create methoid (if implemented by you)
This way you may set defaults or raise events... whatever.
When the object is unset a Destroy method can be invoked, this way you can delete memory or close files and so on.
Basically this is the functionality of a class.
A black box you let do things, it does not conflict with other instances (like a global variable you ever may have used for some purpose) and runs selfcontained.
The way PB creates classes is com based and therefore directly usable for other languages (in the form of a dll).
So the best things are:
1) Maintains private data per instance.
2) Can clean up it's mess, guaranteed in any case (unless when an application crashes).
3) No need to declare functions.. ordinary declarations are daunting!!
There are much more benefits like multiple references and still being guaranteed of proper clean up but that goes beyond this simple explaination.
What i am a bit afraid of is that class are going to be used for any silly functionality.
An ordinary module can be as equally modular as a class.
Several invokes to functions in a module don't have to interfere with each other.
Modules can not create unique instances holding private data.
It's a global variable or a local function variable, nothing else.
Using classes means, will you hold multiple data blocks?
By using a class you won't need to mess with memory pointers to 'make' unique data fragments using an old fashion module.
That a class can have functions is a secundary (but needed) thing.
Btw, remember a type variable could not have dynamic strings?
A class can hold dynamic strings and can be seen as a special type variable.

Comment