Objects vs Functions - is this right?

GWestphal

Golden Member
Jul 22, 2009
1,120
0
76
A function is the same as a method of an object, but the difference is whether the variables (states) are part integrated (object) or not (function).


So, an object is like some black box machine (method) and it has switches on it (states), whereas a function is like a black box that has a shoot on it and I take some other black boxes and drop it in the shoot and it spits out some pyramids.

It that the main difference? Just integration of variables with the function?

Are there any more important differences?
 

cytg111

Lifer
Mar 17, 2008
26,877
16,146
136
Hehehe .. something like that..
... I guess ?! :)

that shit is cracking me up dude, plz continue :).
 

Train

Lifer
Jun 22, 2000
13,599
90
91
www.bing.com
Yes, functions are methods of objects, but there is no rule that says functions can/cannot access state variables within the object itself.

Though typically, if a method/function is not dependant on state of an instance object at all, say for example DateTime.Parse(), it can (or should depending on your OOP philosophy) be made a static method.

Objects are instances of classes, that can contain any combination of methods, properties, fields, etc.
 

cytg111

Lifer
Mar 17, 2008
26,877
16,146
136
You really need to take a hike.

/me likes hiking ..

so this

".. take some other black boxes and drop it in the shoot and it spits out some pyramids."

wasnt intended to be funny? Wasnt funny to you? Maybe you need to grow a sense of humor :)
(and live and let go..)
 

cytg111

Lifer
Mar 17, 2008
26,877
16,146
136
And maybe i am dense, but i seriously do not understand the question.
I'd understand function (returns value) vs. procedure (does not return value, but by reference)
If you're talking Object Oriented vs Functional programming, it is another story alltogether and nothing prevents us from having functions/procedures in either one.

But as I said, i may be dense...

edit : spits out pyramids ... common :)
 

Madwand1

Diamond Member
Jan 23, 2006
3,309
0
76
A function is the same as a method of an object, but the difference is whether the variables (states) are part integrated (object) or not (function).

[...]

Are there any more important differences?

Yes, there are. What you're describing, although not entirely incorrect, is not the main difference between functions and methods -- you could do essentially the same thing with a function by passing it a structure to work on. (And under the hood, this is pretty much what happens even with object-oriented code.)

In object-oriented programming, you should be thinking of higher-level concepts such as high-level encapsulation -- the designer of the class prescribes the methods which are contained in the class definition, and polymorphism -- different derived objects can have different implementations of methods of the same name, and the caller need not be aware of the differences or details.