Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / What are classes?

Author
Message
M00NSHiNE
21
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 22nd May 2004 20:20
Im not a C++ coder or anything, but in my quest for more knowledge I was wondering what classes were (in C++). Its just a niggling thing that bugs me whenever I read tutorials and source that mentions heavy usage of classes - knowing what they are would help me understand better.

Cheers for any help

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 22nd May 2004 20:45
A Class is the blue print for an Object. It's not just a C++ thing, it's an Object Oriented thing. A class is a code file that can contain Methods(funcs and subs), Properties(variables), and Events. In your main code you Instantiate the class as an object where that instance retains all of the base class meths props and events.

It is safe to say DBP has no concept of classes. The only light-weight item in dbp that even remotely resembles an object orient aspect would be a user defined type

If you are familiar with Types then picture being able to bottle up functions, events, other classes into the type - thats kind of the idea behind a class - albeit rudimentary


* DBP_NETLIB_v1.1 - VB.NET PLUGIN FOR DBP * Click Logo
M00NSHiNE
21
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 22nd May 2004 22:00
and an object... whats that?

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 22nd May 2004 22:13
Everything is an object. The object is an instance of the class. So if you have a class Customer

Class Customer

FName as string
LName as string

End Class


then the object would be
XYZ as Customer
xyz.Fname="Joe"
xyz.Lname="Schmoe"

much like a type.
but the class could contain not only properties (like above) but functions and system events as well. Not to mention the Class could INHERIT another class, then build on top of it.

you may wanna look up OOP to get an idea of classes and objects


* DBP_NETLIB_v1.1 - VB.NET PLUGIN FOR DBP * Click Logo
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 22nd May 2004 22:18
An object is an 'instance' that was created/cut from the blue print, that is the class. So you can have various objects of the same class, each totally independent of the other.

Kevin Picone
[url]www.underwaredesign.com[/url]
Play Nice! Play Basic
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 22nd May 2004 22:27
...is what I should have said - LOL


* DBP_NETLIB_v1.1 - VB.NET PLUGIN FOR DBP * Click Logo
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 22nd May 2004 22:38
A class is something that conatains data and methods. That is all.

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 22nd May 2004 22:49
not quite. A class is a framework for an object. It contains Methods, empty Properties, and can Raise Events.

An Object (the INSTANCE of the class) can contain the Data (held in the property buckets), perform actions on the data (methods-functions and subs), and can raise events.


* DBP_NETLIB_v1.1 - VB.NET PLUGIN FOR DBP * Click Logo
Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 23rd May 2004 02:18
I get the basic concept, and this is a stupid question, but what's the poin of bundling functions together when it could just all be one function? Where's the added functionality (no pun intended)?

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 23rd May 2004 02:24 Edited at: 23rd May 2004 02:34
well the class should house it's necessary functions. For example a TCPClient Class might want to have it's own Connect(), Disconnect(), and Send() methods - just as an example.

the class is the core concept of oop. You program can instantiate as many different instances of a class as it needs, each having it's own scope and internal data to use how it needs. Objects can be created, destroyed, and recreated all from one base class, independent of each other.


* DBP_NETLIB_v1.1 - VB.NET PLUGIN FOR DBP * Click Logo
Dgamer
21
Years of Service
User Offline
Joined: 30th Sep 2002
Location:
Posted: 23rd May 2004 02:31
Classes are to C++ as Types are to DB

The statement below is true
The statement above is false
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 23rd May 2004 02:48
Also, a good example is a DLL. A DLL is simply a Class. But the Class doesn't do anything on its own, its the instantiated Object from that class that we are concerned with. In the context of DBP and TPC Dlls, there is no object, no class, just commands (function calls). Behind the scenes however, the DBP main code has taken your DLL and Instanced an object from it - making it available for use.


* DBP_NETLIB_v1.1 - VB.NET PLUGIN FOR DBP * Click Logo
M00NSHiNE
21
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 23rd May 2004 03:02
Ok, I think I understand it now. Thanks to everyone for the input

Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 23rd May 2004 04:10 Edited at: 23rd May 2004 05:54
And now watch my confusing example on how to inherit base classes in your class. This is going to be in Pseudo-code because you probably won't understand C++ and I don't know a way to do it in BASIC.

Your base class may be:



Now we want our next class (for instance, a 'dog') to inherit this because it is an animal and should retain all the animal qualities. To do this, we'd make a new class:



Now if we create an object (or instance of the Dog class), we can call any functions in the animal class and dog class as well as any variables in them also.



This would produce the output:

"Eating!"
"Growling"
"Biting!"
"Tail Length is: 48cm"

So by inheriting a class, you are inheriting all it's functions and variables (methods and members), it can become much more complicated though and you can override the functions in the base class and also inherit multiple classes. And then you have polymorphism where you have a virtual class and god, that'll confuse you.


"Computers are useless they can only give you answers."
Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 23rd May 2004 04:12
Ah, that explains just about everything . Thanks Cattle and Exeat.

M00NSHiNE
21
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 23rd May 2004 04:50 Edited at: 23rd May 2004 04:52
Although you think youve confused me exeat, youve infact just made everything 10 times clearer.

[edit] Actually you were just talking about the last bit, which makes me look stupid

Not the first time anyway

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 23rd May 2004 04:54
Now you know why I asked Exeat to work with me on the plugin...



* DBP_NETLIB_v1.1 - VB.NET PLUGIN FOR DBP * Click Logo
M00NSHiNE
21
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 23rd May 2004 04:59
LOL

Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 23rd May 2004 05:53 Edited at: 23rd May 2004 05:55
Urgh, just realised my space 'tabs' didn't work in my above post. Damn these forums!! Now all the code is bunched together. Let me correct that.

Edit: Fixed, thank god it retains the spaces when you edit the post though. Saved a bunch of time redoing them.


"Computers are useless they can only give you answers."
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 23rd May 2004 05:55
oh well, there goes that theory...

LOL
j/k


* DBP_NETLIB_v1.1 - VB.NET PLUGIN FOR DBP * Click Logo
Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 23rd May 2004 12:37
I probably use bitwise operators 10 times more than I would use classes. It's just a rare thing to find a good use for inheritance...

M00NSHiNE
21
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 23rd May 2004 15:50
Wha..? Bitwise operators?

flibX0r
21
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Western Australia
Posted: 23rd May 2004 16:45 Edited at: 23rd May 2004 16:47
lol

@arkheii

Okay, say you make a base weapon class, made of pure virtual functions. Then you create individual weapon classes that are inherited. In those classes you define the functions, so they are usable. In you main loop, you would have a pointer (of the base class type) that points to a weapon, and you could store pointers in an array, so you could just use a count variable that says which weapon you use, and then you access it through the pointer in the array. This is object orientated weapons (its also polymorphism), and is what i'm using for my current game.

Its not that rare to find a use for inheritance. I've also create a base sprite class that is a layer over DBPro's sprites, and i have inherited classes for text sprites and character sprites.

Classes are my friend

Rob K
Retired Moderator
22
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 23rd May 2004 17:56
@CattleRustler

I think you are confusing things a little. You are explaining the VB.NET definition of a class. VB.NET classes are somewhat different to visual C++.

@Moonshine

Think of an object in real life, like say a car. If you made a C++ class out of a car it would have properties: color, number of wheels, shape, and it would have methods: start(), changeGear(), brake()

The reason classes were introduced is because when a project gets very big (say 100,000+ lines of code), it becomes exceedingly difficult to manage with DBPro-like languages, and a tiny change in one place can result in nasty crashes elsewhere. Also, if someone else came to work on your code they would have no idea how to work with it.

Classes effectively "black-box" parts of your program. You can play around with the internals of a class, and as long as you don't change the bit that is exposed to the outside world, it won't affect the rest of your program.
If someone else comes to work on your code, they only need to know what the inputs and outputs of a class are, they don't need to know how it works inside, in much the same way that you don't have to know what happens when you turn a key in the ignition to start the car. You just know that the engine starts.

There are lots of very fancy names which people talk about with classes, but most of them have fairly simple meanings, such as:

Inheritance - You might have several classes that share certain properties, in which case you create a "parent" class that has all of the common stuff in, and then you create a new "derived" class which can do everything that the parent can do, plus more.

For example, you might have an Animal class which has methods like grow() and fightDisease(). Derived from that could be Cat and Dog classes which have everything that the animal class has, plus methods like woof() or meow() and new properties like numWhiskers.

Polymorphism (Horrible word ) - I use this in my current Blue plugin a lot. The "parent" class for all gadgets is the CGadget class. All gadgets have a create() method which makes the gadget. However, the actual code for create() needs to be different for different types of gadget. Hence I write a create() method for the CGadget class but mark it as Virtual, this means that classes derived from CGadget have their own create() method, and the program should use that instead if it exists.

BlueGUI:Windows UI Plugin - All the power of the windows interface in your DBPro games. - Plus URL download, win dialogs.
Over 140 new commands
Rob K
Retired Moderator
22
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 23rd May 2004 18:02
Quote: " Wha..? Bitwise operators?"


Sounds fancy. In reality its not.

A number in DarkBASIC, and most other programming languages (except Visual BASIC 6) is made up of 4 bytes, or 32 0s and 1s.

The number 2 is written like this for example: 0x10 (A "1" in the 2 column, and a "0" in the 1 column, adds up to 2)

Sometimes you need to change the order of these 1s and 0s or turn the 1s or 0s "on" or "off".

To do this you use BITWISE OPERATORS.

Examples:

AND - If you AND two numbers, the resulting number will have ones only where both the original numbers had ones:

eg: 0x10 BITWISE AND 0x11 --> 0x10

XOR - If you XOR two numbers, the resulting number will have ones where either (but not both) of the original numbers had ones:

eg: 0x01 BITWISE XOR 0x01 --> 0x00

BlueGUI:Windows UI Plugin - All the power of the windows interface in your DBPro games. - Plus URL download, win dialogs.
Over 140 new commands
flibX0r
21
Years of Service
User Offline
Joined: 14th Feb 2003
Location: Western Australia
Posted: 23rd May 2004 18:06
i like making pure vitual functions, mainly cos it sounds cool, but also so if the base class if supposed to be empty, then it is (like the word polymorphism too )

Tomy
20
Years of Service
User Offline
Joined: 25th Dec 2003
Location:
Posted: 23rd May 2004 18:48 Edited at: 23rd May 2004 19:10
Quote: "Classes are to C++ as Types are to DB"


well, not really...
types are just another way of storing data (that's why they're called data types) whereas in C++ classes have methods which can contain everything: ie. you could make a class fighter, make and object Max from it and then call max.punch. this however would be impossible with DBP...

Just to clarify: objects are just representatives of classes, like ie. you have a fighter Max and a fighter Brad.. Max and Brad are then objects from the class fighter.

Moreover the classes always "inherit" from another class in the definition, getting all the methods the other class has.
Ie. you could make a class "human" and then make a class "player" which "inherits" all the methods from "human".

All in all DBP is NOT an OOP Language, so you can't find anything that's similar to classes in DBP...

Quote: "And now watch my confusing example on how to inherit base classes in your class. This is going to be in Pseudo-code because you probably won't understand C++ and I don't know a way to do it in BASIC."


There is no way to do it in BASIC

[EDIT]oh RobK already mentioned quite a lot what i've just said... sorry


GameVisions Softwares - http://www.gamevisions.cbj.net
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 23rd May 2004 19:02
@RobK, I was speaking from my experience which is vb/vb.net. I think I generalized concept of classes enough to just get the point across, without being a c++ coder. Sorry if I treaded on some sacred territory


* DBP_NETLIB_v1.1 - VB.NET PLUGIN FOR DBP * Click Logo
M00NSHiNE
21
Years of Service
User Offline
Joined: 4th Aug 2003
Location: England, UK
Posted: 23rd May 2004 19:15
Thanks everyone, I understand now.

Login to post a reply

Server time is: 2024-09-22 00:28:31
Your offset time is: 2024-09-22 00:28:31