Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CrazyIllini

macrumors member
Original poster
Oct 8, 2009
57
0
So I have no programming experience and am reading a book (not taking a class) on Objective-C. In one of the first chapters they try to explain the terms clases, objects, methods and instances. I feel like I don't fully understand what they are trying to say and I would like another explanation.

And I DID check Mroogle.
 
Which book? Be specific.

Which parts of the explanation didn't you understand? Be specific.

When asking programming questions, it's usually better to be specific instead of general. For example, saying exactly which book, saying exactly what you didn't understand (even quoting the text instead of paraphrasing it), or posting actual code instead of posting a description of it.

http://www.mikeash.com/getting_answers.html
 
Check out the java versions of classes and objects. The concept of OOP should be very similar.
 
People seem hesitant to answer this, and I'm not quite sure why.

A method is a set of code that is defined as part of a class. It performs some task, and optionally returns a value. It generally operates on class or instance variables.

A class is a set of methods and variables. This is used to encapsulate related data and actions on that data. Often this is used to model a real-world item like a car, shape, or animal.

An instance or Object refers to a concrete example of a class. These are the foundation of Object-Oriented Programming. Where a class is like a plan or idea, an object is a single item that is built from that plan. For example, a single German shepherd named Brüno.

A method is most commonly used to act on an object/instance such as "walk" or "call" on a dog. This is called an instance method. There are methods that act on a class, such as "getPhylum" on the dog class. These are called class methods.

Variables can also be tied to a class or instance. For example, the dog class might have a class variable to hold it's phylum, or return a list of all dog instances you've created. An instance variable would hold information about one single dog, like it's name, breed, etc.

-Lee
 
Which book? Be specific.

Which parts of the explanation didn't you understand? Be specific.

When asking programming questions, it's usually better to be specific instead of general. For example, saying exactly which book, saying exactly what you didn't understand (even quoting the text instead of paraphrasing it), or posting actual code instead of posting a description of it.

http://www.mikeash.com/getting_answers.html


Sorry the name of the book was Programming in Objective-C 2.0 by Stephan G. Kochan.



People seem hesitant to answer this, and I'm not quite sure why.

A method is a set of code that is defined as part of a class. It performs some task, and optionally returns a value. It generally operates on class or instance variables.

A class is a set of methods and variables. This is used to encapsulate related data and actions on that data. Often this is used to model a real-world item like a car, shape, or animal.

An instance or Object refers to a concrete example of a class. These are the foundation of Object-Oriented Programming. Where a class is like a plan or idea, an object is a single item that is built from that plan. For example, a single German shepherd named Brüno.

A method is most commonly used to act on an object/instance such as "walk" or "call" on a dog. This is called an instance method. There are methods that act on a class, such as "getPhylum" on the dog class. These are called class methods.

Variables can also be tied to a class or instance. For example, the dog class might have a class variable to hold it's phylum, or return a list of all dog instances you've created. An instance variable would hold information about one single dog, like it's name, breed, etc.

-Lee


Thank you. That was exactly what I was looking for.
 
If it can help:
Objects: ... well those are "things" :) like in a real life. For example a car

Classes: I would say that it is the same as Objects.

Instance of an object: it is one object in particualar. For example your car. Another instance is the car of your neighbor. They are all cars but different instances.

Methods: are actions you can perform on an Object:
- start up the engine
- open window
- break
- ...

Instance variables: properties that define one car in particular (one instance of a car). For example the color is an instance variable. Your colors is red, the color of the neighbor s car is green. So instance variables differ from one instance to another.


Hope it helps ;)
Tex
 
My car object keeps receiving the -break method. Not sure how much longer I can afford to fix it.
 
My car object keeps receiving the -break method. Not sure how much longer I can afford to fix it.

You obviously didn't document your class clearly. Others are desperately sending the "-break" message hoping that it will result in the car stopping, but instead it results in your car being damaged.

My recommendation would be to publish a method "-applyBrakes" that slows down/stops the car, and make a private (as private as you can make it in Obj-C, at least) method "-damageCar". This should cut down on the confusion and repair costs.

-Lee
 
You obviously didn't document your class clearly. Others are desperately sending the "-break" message hoping that it will result in the car stopping, but instead it results in your car being damaged.

My recommendation would be to publish a method "-applyBrakes" that slows down/stops the car, and make a private (as private as you can make it in Obj-C, at least) method "-damageCar". This should cut down on the confusion and repair costs.

-Lee

What I really need is +applyBrakes, but that one is rather difficult to implement.
 
You obviously didn't document your class clearly. Others are desperately sending the "-break" message hoping that it will result in the car stopping, but instead it results in your car being damaged.

My recommendation would be to publish a method "-applyBrakes" that slows down/stops the car, and make a private (as private as you can make it in Obj-C, at least) method "-damageCar". This should cut down on the confusion and repair costs.

-Lee

Nice.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.