why classes and objects are similar in objective c

Joined
Mar 8, 2010
Messages
1
Reaction score
0
Points
1
I'm new to objective c.i got trough the point that objects and classes are same in objective c.i'm not getting this point how they can be same....

i need the explaination....


plzz reply mee......
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
I'm not sure what you are asking. Typically a class is useless without being instantiated into an object. A few classes can be useful without creating an object.

In object oriented languages, a class is a template for objects that will be based on it. You create objects by instantiating them from the class. The act of instantiating sets aside space for the variables you declared in the PERSON class, along with others that were inherited. So, if you have a PERSON class, you can create one or more PERSON objects (Frank, Kimberly, Jason) that use the model of PERSON. When you tell Frank to set his age to 32, you are using the method you wrote in the PERSON class, but it only affects age variable the Frank object. Kimberly and Jason have their own age variables.

I can't think of a short way of describing this all, so I point you to the following...

See Apples "The Objective-C Programming Language". On the left click on "Objects, Classes, and Messaging".

"Becoming an XCoder" might be useful too. Search for class and object. Perhaps page 37.
 
Joined
May 10, 2010
Messages
10
Reaction score
1
Points
3
The above post is not quite correct and is confusing instances of objects and the concept of an object.

A class IS an object. A class is just a way of denoting what the object is specifically. For instance if I said, "I have a thing." You know I have something but you don't know what. If I say, "I have a kitten." You know specifically what kind of thing I have. You don't know anything about a "thing" or what it might do but you do know a kitten will, probably, have fur and purr.

In the most basic of terms objects are things that have methods and properties (I'll avoid the idea of events to keep it simple). Then can be told to do things and they can have values associated with them. The word object describes that idea of having properties and methods. By itself it is just a concept.

A class then goes a step further and describes what kind of object a thing is, like a dog or a tree, and describes what methods and properties that object has. Like a dog might have a bark() method and a canBark property while a tree might have a shedLeaves() method and an isDeciduous property but a dog wouldn't shed leaves and trees don't bark; not even a dogwood.

So far we've talked about the idea of things but we haven't talked about how you get a copy of this idea of an object, what is called an instance. When you instantiate a class you create a copy of an object of type class which can then be manipulated.

Think of a class a blueprint. A blueprint is not a house itself but describes what a house should look like. When you build your house, when you instantiate it, you can then paint it, which is changing one of its properties, and you can turn on the airconditioner, which would be like using one of it's methods.

So, to recap a class IS an object, it's just a specific description of a KIND of object, while an instance is a copy of a class that can be manipulated.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top