V4 - OOP

Share your advanced PureBasic knowledge/code with the community.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

:?

OK, so apart from being something I wagged in school, classes are what? A way to allow multiple, um, declarations (or whatever term) of an object, as in fsw's linked list? Creating several instances of the object?

I'm missing something, but what difference between an object definition and a class? Surely you can define multiple instances of the object without classing it? It Class just a sexy way to say that?

So we have an object (definition).
We have an instance (usable entity).
We have a class. (Which sounds classier than creating an instance)

And a subclass is then what - tacking an object definition to another object definition? But in a cool way?


* takes a headache tablet *


Also, is there a way, via interfaces, to dynamically access one of the procedures in the datalist? Without actually referring to it by name?

For example, using CallFunctionFast(?procedures + (n * 4)) will access the nth procedure in the list. Can something like this be done using the interface/oop-ish approach being explored here?

Or are we stuck with (the still usable but now deprecated) callfunctionfast?
@}--`--,-- A rose by any other name ..
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Class: Homo Sapiens (main, or super class)

Subclassed object: Male Human being (inherits some of the methods & properties of Homo Sapiens)
Subclassed object: Female Human being (warning - yours might react badly to being called a subclassed object)

Instance: Dick Cheney, with his own unique subset:

Method: Grab_Oil()
Method: Hunt_Quail()

Property: Height
Property: Weight
Property: Aiming Ability

Object Oriented Programming is merely an attempt to mimic the behaviours and relationships found in real life in a software program. The concepts, as you can see, are really not obscure or difficult. How far you choose to take the concept in your programs is entirely a personal choice. For myself, I don't plan on getting too carried away. Like any good thing, a little goes a long way and too much can land you in trouble.
Last edited by netmaestro on Thu Feb 23, 2006 7:05 am, edited 4 times in total.
BERESHEIT
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

netmaestro wrote:Object Oriented Programming is merely an attempt to mimic the behaviours and relationships found in real life in a software program. The concepts, as you can see, are really not obscure or difficult. How far you choose to take the concept in your programs is entirely a personal choice. For myself, I don't plan on getting too carried away. Like any good thing, a little goes a long way and too much can land you in trouble.
Agree with that.
Moreover, OOP is no useful for some kinds of aplications, like simulations or general scientific oriented programs, which is my case.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Psychophanta wrote:
netmaestro wrote:Object Oriented Programming is merely an attempt to mimic the behaviours and relationships found in real life in a software program. The concepts, as you can see, are really not obscure or difficult. How far you choose to take the concept in your programs is entirely a personal choice. For myself, I don't plan on getting too carried away. Like any good thing, a little goes a long way and too much can land you in trouble.
Agree with that.
Moreover, OOP is no useful for some kinds of aplications, like simulations or general scientific oriented programs, which is my case.
Agreed! OOP can be very useful to solve complicated problems but IMHO can make code slow and bloated if over used. For example i have seen programs attempting code re-use by re-using a class which didn't really do what was needed. A subclass was made from this superclass and then more properties and methods were added. This was then used in the code but only a fraction of the superclass's methods was used. So we have lots of stuff defined but never used in the current program. In these situations i think it's better to code a new class or maybe it can be done cleaner without OOP.
--Kale

Image
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

@netmaestro

Love your examples. :) But quail a bit about having Cheney in the Homo Sapiens class.

Actually I got all excited here on two fronts, first being the possibility of (more) easily using C++ and other OOP libs. Second, more important to me right now, was a way to create a jumptable without using CallFunctionFast (as, at bottom, OOP is a glorified jumptable with attitude).

Unfortunately I can't see how to use this for either. Not saying it can't be done, just saying I can't see how it can be done. I can follow the code you guys are posting, I can even see some resemblences to oop, but I can't quite see the way it can be meshed with an Oop. And I can't see a way to do dynamic (via jumptable) calls either. C'est la vie.

But this hijacks the thread a bit, so I'll leave off as the subject is very interesting and getting some decent coverage here.
@}--`--,-- A rose by any other name ..
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

netmaestro wrote: Instance: Dick Cheney, with his own unique subset:

Method: Grab_Oil()
Method: Hunt_Quail()

Property: Height
Property: Weight
Property: Aiming Ability
Nice example netmaestro, but just to clarify for others - Height and Weight are not unique to the Dick Cheney subset, but are subclassed from some pre-Homo Sapien object.

Man, I feel like a total geek right now after I wrote that.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

I'm getting into this OOP ..

Can we do some OOP for Dummies.. like me..

I rewrote your whole dog thing.. into a human thing.. just to start
wrapping my head around it.

How about a few small examples using the Interface.. as that I have
never made much use of it.. but after working with it in these examples,
I don't know how I've lived without it.

Some simple examples please.. if possible.. A lot of people can only
benefit from this.. ;)

- np
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

From the tutorial section of PureArea.net:

http://drac.site.chez-alice.fr/Tutorial ... als_en.htm
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

Straker wrote:From the tutorial section of PureArea.net:

http://drac.site.chez-alice.fr/Tutorial ... als_en.htm
This one is old and for the 3.xx.
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

Bonne_den_kule wrote:
Straker wrote:From the tutorial section of PureArea.net:

http://drac.site.chez-alice.fr/Tutorial ... als_en.htm
This one is old and for the 3.xx.
But it covers concepts well that can be used in any language. Besides, are you sure that the code doesn't work in 4.x (which is still beta btw)?

Like all matters of learning, glean from it what you can, apply what works for you, and ignore the rest.

IMO, it is still a valid tutorial.
Bonne_den_kule
Addict
Addict
Posts: 841
Joined: Mon Jun 07, 2004 7:10 pm

Post by Bonne_den_kule »

:oops:
Your right, but isent OOP easyer and cleaner in pb4?
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Straker wrote:From the tutorial section of PureArea.net:

http://drac.site.chez-alice.fr/Tutorial ... als_en.htm
Hi Straker, that is excellent doc. Who is the author?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Seems it's Dräc.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Straker
Enthusiast
Enthusiast
Posts: 701
Joined: Wed Apr 13, 2005 10:45 pm
Location: Idaho, USA

Post by Straker »

Bonne_den_kule wrote::oops:
Your right, but isent OOP easyer and cleaner in pb4?
I don't know yet. From what I have seen so far, yes, however, these new techniques are still in flux because it is still beta. I am waiting for 4.0 to be released before I expect to see a concrete methodology.
Flype wrote: Seems it's Dräc.
yes.
hellhound66
Enthusiast
Enthusiast
Posts: 119
Joined: Tue Feb 21, 2006 12:37 pm

Post by hellhound66 »

Removed.
Last edited by hellhound66 on Wed Mar 19, 2008 11:48 pm, edited 1 time in total.
Post Reply