views:

259

answers:

5

Hi,

As you may have guessed from the question - I am right at the beginning of the Obj-C journey.

I'm hoping that someone out there knows of some diagrams that depict the relationship between classes, objects and methods - and that they're willing to share.

The problem I'm having is that just looking at code in a textbook doesn't completely explain it - for me at least.

Thanks for reading!

Regards, Spencer.

+2  A: 

Classes are just like classes in any language. They are descriptions.

Objects are like nouns. They are an instance of a class. That is, if you had a description of a generic book (the class) and you made a thesaurus based on that description, the thesaurus would be the object.

Methods are more or less functions. If the objects are nouns, then the messages are verbs.

[ScienceBook getTableOfContents]; //this would like return a table of contents.

Here, the object ScienceBook is being sent a getTableOfContents message (method). So now, the science book would theoretically find, format and return the table of contents to whom ever sent the message.

Kailoa Kadano
Kailoa Kadano! Thanks!
Spencer
+2  A: 

To some extent, diagrams may not be that helpful to answer the questions you present.

It may help to think of things like this:

A "class" provides the prototype or definition for some thing. For example, a "Person" or a "Car". A common synonym for "class" is "type".

An "object" is a concrete example or instance of a class. For example, you are an instance of "Person", and your car is an instance of "Car".

A "method" is a behavior, action or property of a class. However, a method is normally only meaningful in the context of an object. "Person" -> "Eat" is not meaningful, but "you" -> "Eat" is.

These are fundamental Object-Oriented concepts that are not specific to Objective-C. If you are interested in a general overview that is language-agnostic, I recommend "Object Thinking" by David West. Even though it's from Microsoft Press, it covers the concepts rather than any specific language.

GalacticCowboy
Thanks Galactic Cowboy! I really appreciate your advice.Cheers,Spencer.
Spencer
+3  A: 

No diagrams, but this is the tutorial I wish I'd read before I started: http://www.cocoadevcentral.com/d/learn_objectivec/

Simple English, all the basic concepts.

Justicle
Thanks so much for the help Justicle!
Spencer
+2  A: 

I come from a fairly strong C++ background, but I can definitely remember when I started, I had a hard time grasping at the concept until I found a way to associate it with physical objects.

The word class and object you can use almost interchangeably. Think of an object as a container, like a bucket. The word bucket would be your "class". It is the name you give to the type of object you have.

A bucket has a certain purpose...to carry something. It might be water...or perhaps sand. So perhaps you want to fill the bucket. This would be something you do to the bucket, so in objective-c, this would be your method. You might write something like:

- (void) fillWith:(elementType)something;

So in this case, "something" might be something that represents and object you wish to fill your bucket with.

Your class might look like the following:

typedef enum items {
   CRAYONS,
   MARKERS,
   SAND,
   WATER } elementType;


@class Bucket {
   elementType item;
}
- (void) fillWith:(elementType)something;

@end

Here's one link to some objective-c samples. Also try the apple development center.

Gary
Thank you for the help Gary!
Spencer
A: 

If you're after information on Object Orientated Programming (ie the meaning of classes, objects, methods etc) then I'd advise against Objective-C. Objective-C on the Mac relies heavily on the Cocoa framework. The Cocoa framework is vast and performs a lot of 'magic' which will make it harder to understand the fundamentals of OOP.

An easier place to start would be a language used for web development. It's easier to get to the nuts and bolts of OOP with these languages.

Benedict Cohen
Hi Benedict - thanks. I'm learning Objective-C as a standalone language and will learn Cocoa later.Cheers,Spencer.
Spencer
It is getting intentionally (and almost necessarily) more difficult to separate framework elements from their underlying languages. For example, Visual Basic and C# are nearly inseparable from .Net. You rarely say Ruby without "on Rails." Python and PHP exist more or less on their own even though high quality frameworks are available for them making them good potential languages for new developers. Of the two, I would suggest Python as it will create fewer bad habits down the line and will likely (hopefully) displace PHP in the not-so-distant future.
Rob Allen