Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-09-2010, 08:52 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 7
nexus is on a distinguished road
Exclamation Understanding OOP

Ok, I'm understanding the basic concepts in OOP. In Objective C I know how to create a class, write methods for that class and basic message passing.

I guess my confusion lies within the semantics. When I create a class, I do the following:
Code:
@interface Fraction : NSObject //NSObject is the parent class to our Fraction class
{
	// delcare instance variables for our class
	int numerator;
	int denominator;
	int fractionType;
}

//method headers

- (void) myPrintMethod;
- (void) mySetNumeratorMethod:		(int) n;
- (void) mySetDenominatorMethod:	(int) d;

@end
So, when a class is created, we assign it to NSObject. I think that's what's throwing me. Our class is a child of the parent NSObject, so what is the difference between classes and objects?

Last edited by nexus; 04-09-2010 at 10:45 PM.
nexus is offline   Reply With Quote
Old 04-10-2010, 12:46 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

> So, when a class is created, we assign it to NSObject

You mean your Fraction class is extending or subclassing NSObject.

> Our class is a child of the parent NSObject,

True.

> So what is the difference between classes and objects?

A class is a template or plan for creating objects; kind of like a blueprint. You might make a single blueprint but then build six houses from it. The blueprint is your class, and the houses are your objects (also called instances).

In your case you've created your Fraction class; now you might alloc and init two or two or a hundred objects (instances) of that class and put different data in each one.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 04-10-2010, 06:09 AM   #3 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 7
nexus is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
> So, when a class is created, we assign it to NSObject

You mean your Fraction class is extending or subclassing NSObject.

> Our class is a child of the parent NSObject,

True.

> So what is the difference between classes and objects?

A class is a template or plan for creating objects; kind of like a blueprint. You might make a single blueprint but then build six houses from it. The blueprint is your class, and the houses are your objects (also called instances).

In your case you've created your Fraction class; now you might alloc and init two or two or a hundred objects (instances) of that class and put different data in each one.
Smasher,

Thank you for clearing that up. I went over to this very popular online video learning center (not sure If i'm allowed to mention the name here) and I now have a solid understanding of classes, objects, messages.

Thanks again.
nexus is offline   Reply With Quote
Reply

Bookmarks

Tags
class, method, object, oop

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 464
14 members and 450 guests
7twenty7, AlanFloyd, David-T, imac74, Jaxen66, logan, lovoyl, Music Man, mutantskin, Sami Gh, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:08 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0