Objective-C newbie: Does anyone know charts that explain class, objects, and methods?

As you might have guessed from the question - I'm right at the start of the Obj-C journey.

I hope someone out there knows some diagrams that depict the relationship between classes, objects, and methods — and that they are willing to share.

The problem I ran into is that just looking at the code in the tutorial doesn’t fully explain this - at least for me.

Thank you for reading!

Regards, Spencer.

+4
source share
5 answers

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

Objects are similar to nouns. This is an instance of the class. That is, if you had a description of the general book (class), and you created a thesaurus based on this description, then the thesaurus would be an object.

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

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

Here the ScienceBook object ScienceBook message. So, a scientific book theoretically found, formatted, and returned the table of contents to which a message was ever sent.

+2
source

There are no diagrams, but this is a tutorial that I would like to read before starting work: http://www.cocoadevcentral.com/d/learn_objectivec/

Simple English, all basic concepts.

+7
source

To some extent, the charts may not be so useful for answering the questions you have provided.

It may help to think about such things:

A "class" provides a prototype or definition for some things. For example, "Man" or "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 usually only makes sense in the context of an object. “Face” → “Eat” does not make sense, but “you” → “Eat”.

These are fundamental object-oriented concepts that are not related to Objective-C. If you are interested in a general overview, which is a language agnostic, I recommend David West's “ Object Thinking ”. Although it's from Microsoft Press, it covers concepts, not just any specific language.

+2
source

I come from a fairly strong background in C ++, but I can definitely remember when I started, it was hard for me to grab onto the concept until I found a way to associate it with physical objects.

The class and object of a word that you can use is almost interchangeable. Think of the object as a container, as a bucket. The word bucket will be your class. This is the name that you point to the type of object that you have.

The bucket has a specific purpose ... to carry something. It could be water ... or sand. Therefore, perhaps you want to fill the bucket. This will be what you do with the bucket, so in objective-c this will be your method. You can write something like:

 - (void) fillWith:(elementType)something; 

So, in this case, “something” may be something that represents the object that you want to fill with your bucket.

Your class might look like this:

 typedef enum items { CRAYONS, MARKERS, SAND, WATER } elementType; @class Bucket { elementType item; } - (void) fillWith:(elementType)something; @end 

Here is one link for some objective-c samples. Also try the apple development center.

+2
source

If you provided information about object-oriented programming (i.e. the meaning of classes, objects, methods, etc.), I would advise against Objective-C. Objective-C on Mac is heavily dependent on Cocoa's structure. Cocoa's framework is extensive and does a lot of “magic”, making it difficult to understand the basics of OOP.

An easier place to start is the language used for web development. Easier to get to the OOP nuts and bolts with these languages.

0
source

Source: https://habr.com/ru/post/1286727/


All Articles