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

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 9, 2008, 01:49 AM   #1
larswik
macrumors 65816
 
Join Date: Sep 2006
Page 25, Objects

The book uses examples and says think of objects as things like a CAR. It is saying that CAR is the name of the CLASS from which I create an INSTANCE of that car.

Now from what I understand an INSTANCE is like a copy of the original that you work with, correct? Am I to assume that I work with instances because I can not change the original class or it keeps me from screwing it up?

Thanks,

-Lars
larswik is offline   0 Reply With Quote
Old Apr 9, 2008, 01:56 AM   #2
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Quote:
Originally Posted by larswik View Post
The book uses examples and says think of objects as things like a CAR. It is saying that CAR is the name of the CLASS from which I create an INSTANCE of that car.

Now from what I understand an INSTANCE is like a copy of the original that you work with, correct? Am I to assume that I work with instances because I can not change the original class or it keeps me from screwing it up?

Thanks,

-Lars
If you have class car then an instance of that class would be a Ford Focus or Mazda MX5. The class is something that describes a group of items and an instance is a specific example of that class.

A class is there to describe general rules for that group. So in the car example it would say they had 4 wheels, a steering wheel etc.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Apr 9, 2008, 02:06 AM   #3
larswik
Thread Starter
macrumors 65816
 
Join Date: Sep 2006
I understand. On the next page he did use that example with wheels, washing it and so on.

His example was Class Car and my instance was MY CAR and the instance method was DRIVE, WASH IT, FILL GAS and so on. He said finding out how many different cars the manufacture has with be a Class method

That was a fast response!

Thanks,

-Lars
larswik is offline   0 Reply With Quote
Old Apr 9, 2008, 02:43 AM   #4
Cromulent
macrumors 603
 
Cromulent's Avatar
 
Join Date: Oct 2006
Location: The Land of Hope and Glory
Quote:
Originally Posted by larswik View Post
I understand. On the next page he did use that example with wheels, washing it and so on.

His example was Class Car and my instance was MY CAR and the instance method was DRIVE, WASH IT, FILL GAS and so on. He said finding out how many different cars the manufacture has with be a Class method

That was a fast response!

Thanks,

-Lars
Also it is important to remember that instances inherit the values of the class that they are a member of. So you should in theory only have to specify the generalities in one class only. Design seems to be the number one most important factor in OOP (much more so than in procedural programming although it is obviously important there).

I really need to pull my finger out and do some OOP stuff.
__________________
Neural Advance - Mac OS X, UNIX and Windows Development
Last.fm Profile | Extreme Metal Reviews
MP 4x 2.66Ghz Xeons / 6GB RAM / 640GB + 500GB + 750GB + 1TB HDDs / ATI Radeon 4870 / iPad 3
Cromulent is offline   0 Reply With Quote
Old Apr 9, 2008, 05:39 AM   #5
cmaier
macrumors G3
 
Join Date: Jul 2007
Location: California
Think of the class like a blueprint for a car. The blueprint isn't useful for anything other than for churning out cars.

You can look at the blueprint and say, hey, when that's built, here's how I'll wash it, and here's how i'll steer it, and it will have properties like color and speed, etc. But until you actually get through the factory, there are no cars.

Or something :-)

Of course, "class methods" break this idea a little bit, but not entirely. Class methods are simply things that all cars share. That is to say, there is only a single instance of the method amongst all the cars. Like no matter how many cars you have side-by-side, when they tune their radios to 98.6, they all are forced to suffer and listen to the same class radio station.

Class methods are not used as often as programming books suggest. Some places I've used them:

constants. For example, I might define a class called MyColor. Then I might have class functions:

MyColor.red()
MyColor.blue()
MyColor.green()
etc.

"red" means the same thing always, so if it's a complex structure I only need to allocate memory for it once.
__________________
applenews.zone
Discussion of microprocessors and other technology, and reviews of tech products.

Last edited by cmaier; Apr 9, 2008 at 05:45 AM.
cmaier is offline   0 Reply With Quote
Old Apr 9, 2008, 01:08 PM   #6
larswik
Thread Starter
macrumors 65816
 
Join Date: Sep 2006
Thanks, the book is starting to go in depth about this to give me a clear understanding.

-Lars
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
OpenGL ES: Vertex Buffer Objects and Vertex Array Objects Blakeasd iPhone/iPad Programming 2 Jul 12, 2013 11:24 PM
MS Word - Insert landscape page (page break not working) foxdougan Mac Applications and Mac App Store 2 Jun 17, 2013 08:28 AM
make safari 5 always open a new page when launched, and just my home page aPple nErd Mac OS X 10.7 Lion 8 May 5, 2013 02:11 PM
Virtual Memory Swap Page-in Page-out Question elberto1 MacBook Pro 5 Sep 10, 2012 08:21 PM
safari can't open the page because the server where this page is located isn't respon Paulshaqz OS X 10.8 Mountain Lion 0 Aug 17, 2012 02:16 PM

Forum Jump

All times are GMT -5. The time now is 04:45 PM.

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

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