Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 10-21-2004, 07:39 PM   #1 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default Classes VS Functions

I'm just wondering if anyone could spare a minute and explain this to me...

Is the only difference between the two...
classes: variables are stored only within itself
functions: variables are global throughout the script

Just curious
thanks,
X
__________________
Vormund is offline  
Old 10-23-2004, 10:42 AM   #2 (permalink)
 
Ultra Techie

Join Date: Sep 2003

Location: Bamberg, Germany

Posts: 549

Iron_Cross

Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

What language are you talking about? In Java or C# that's not true. Functions are local and can only be called within the function itself unless they're returned to the calling function.

Classes are templates, which the variables are either local, or global.

A function is a subroutine, a class is a template for an object...kind ofo like a blue print.
__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline  
Old 11-03-2004, 02:01 PM   #3 (permalink)
 
True Techie

Join Date: Apr 2004

Posts: 168

nak-1

Default

Just in case you don't know what an object is, in Object Orientated programming, generally OO for short, data comes along with the functions you use on that data. ie. a number object will have a place to store the number and a load of functions that do something with it. For instance in OO you would pass the number object a message to return the number, or add another number to it or countless other things. The class determines how the object works, ie. what variables it needs and what functions. This definition does two things, it describes an interface so that other objects know how to talk to the object and, like Iron Cross said, it provides a blue print from which to create initial copies of the object as they are needed by running programs.

If your going to be pedantic about OO you would not want global variables within an object as that sort of destroys the point of OO programming. You define the interface to an object so that you can pass it messages and get an expected result, what's actually done within the object doesn't really matter as long as it gets the job done and hence can be changed at any time without impacting the rest of your code. However if you rely on outside access to the internal structure of your object, a global variable for instance, changing that structure can cause real headaches with the rest of your code. however people use these things because they provide real shortcuts in terms of algorithm design.
Some languages allow this and some don't or at least they say they don't but if you are using a C derivative you can basically do anything you want with memory locations through the use of pointers.
__________________
--------------------

Nak

Is it just me, or does something smell suspicious about all this?
nak-1 is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On