Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 17, 2011, 04:54 PM   #1
larswik
macrumors 65816
 
Join Date: Sep 2006
Things in Objects.

After I read the Learn C on Mac book I took the Pascal class at my local City College. One thing I learned there was to keep my 'Main' clean looking and send out Procedures and Functions for processing and return the data. This made the code easier to read.

One thing jiminaus mentioned in another thread I had was that NSLog was a Function and not a Method. So that I have my terminology right. A Method is just simply procedural code, that performs a task and returns the result. I can pass a parameter from Main, to a Method in an object, and return a result back to Main again(keeping it simple). That Method could be anything from just storing a simple Integer to a Function or some very complex procedure.

-Lars
larswik is offline   0 Reply With Quote
Old Jun 17, 2011, 05:41 PM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
A method is a "function" within the scope of an object. A function is simply a procedural call. So it's basically a difference of programming paradigm.
robbieduncan is offline   0 Reply With Quote
Old Jun 17, 2011, 06:10 PM   #3
larswik
Thread Starter
macrumors 65816
 
Join Date: Sep 2006
That I grasp now, Methods are just Functions. Thanks.
larswik is offline   0 Reply With Quote
Old Jun 17, 2011, 06:14 PM   #4
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by larswik View Post
A Method is just simply procedural code, that performs a task and returns the result.
That sounds more like the difference between a subroutine (void function in C) and function.

Methods are functions that operate on objects.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Jun 17, 2011, 07:41 PM   #5
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by balamw View Post
Methods are functions that operate on objects.
Except you can define functions that operate on objects, too. For example:
Code:
void funky( int foo, NSMutableString * bar, float bazz );
Or consider NSLog(), which is a function that operates on objects.


I often find it useful to look up terms using Wikipedia. Even if I disagree with their definition, I frequently find the discussion and rationale useful.
http://en.wikipedia.org/wiki/Method_...er_programming)
In object-oriented programming, a method is a subroutine that is exclusively associated either with a class (in which case it is called a class method or a static method) or with an object (in which case it is an instance method).
For example, every class descended from NSObject has a -description method. The effect is that every object of every descendant class can respond to the -description message. Classes can override the inherited method, causing only instances of that class to always perform the new method.
chown33 is online now   0 Reply With Quote
Old Jun 17, 2011, 08:16 PM   #6
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
It's the "exclusivity" that's harder to pin down.

e.g. an accessor method is a function that generally takes an object and has a return value associated with the state of the object.

However, it typically doesn't modify the object, and its return value is generally not an object...

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Jun 19, 2011, 10:06 AM   #7
Sydde
macrumors 68000
 
Sydde's Avatar
 
Join Date: Aug 2009
I look at it this way: an object instance is the context in which a method runs. The method can see the instance variables defined in the @interface section. A function does not have any private persistent context (unless you define a static within its scope), only whatever you give it when you call it.

When you send a message (call a method), the underlying Objective-C processes have to find the method (usually very quickly), load the context (the pointer to the receiving object) and run the code. A function begins much more quickly because the location of its code is already know and there is no context to load. With Objective-C, you sacrifice a small amount of run time to gain a lot of flexibility.
Sydde is offline   0 Reply With Quote
Old Jun 19, 2011, 11:44 PM   #8
GorillaPaws
macrumors 6502a
 
GorillaPaws's Avatar
 
Join Date: Oct 2003
Location: Richmond, VA
If you think of objects as actors in a play you're writing, then methods are messages between the objects (dialogue between actors), or messages to themselves (monologues). Class methods in this analogy take on a meta role and might be something like, how many actors do we have to play the Hamlet role in this year's broadway production? let's fire John Doe from the Hamlet role and cast Will Smith for the part instead, etc.
__________________
How to ask good programming questions: Getting Answers
GorillaPaws is offline   0 Reply With Quote
Old Jun 20, 2011, 02:04 AM   #9
larswik
Thread Starter
macrumors 65816
 
Join Date: Sep 2006
Thanks for you help
larswik is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Objects in Objective C luke71933 Mac Programming 6 Apr 8, 2014 08:20 AM
OpenGL ES: Vertex Buffer Objects and Vertex Array Objects Blakeasd iPhone/iPad Programming 2 Jul 12, 2013 11:24 PM
Creating Objects on the Fly tdewitt274 iPhone and iPod touch Apps 1 Nov 4, 2012 11:25 AM
LR -> PS as smart objects patent10021 Digital Photography 1 Oct 17, 2012 03:44 PM
Things you like vs things you don't like in iOS 6! MacMane iPad 8 Sep 20, 2012 08:48 PM

Forum Jump

All times are GMT -5. The time now is 01:07 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC