seriypshick said:
Thanks, Everyone. I think I got it now.
Just want to double check on theese:
Class - Where you define methods variables, or something like blueprint for objects.
Object = Instance of class(or copy of class) + you can send variable to objects like we do w/functions. The diference is syntax.
Function:
Code:
function(varable1, variable2);
OOP:
Code:
[objectName getVariableX: variable1]
[objectName getVariableY: variable2]
Did I get it right?
Others have answered your questions above, I'll just add on my bit of advice here. Don't get too hung up on the terminology, it's far more important to understand the concepts and the reasons behind OOP.
Classes/Objects/Instances
Perhaps its easiest if you take an example: let's say you are writing a new address book. You probably will create a new class called "Person" (or 'PersonalDetails' or...), with member variables (name, address, phone number etc), plus methods to set and retrieve these variables (name, getName etc.) plus perhaps to write them to disk/read from disk.
Now, you have effectively created a new 'data type' called Person, which also includes (encapsulates) the code to manage that data. This "encapsulation" is one of the key advantages of OOP. What if you wanted to change the phone number variable to store numbers in international format, you probably just need to change the phoneNumber, setPhoneNumber methods. If you weren't using OOP/classes, you'd probably need to scour your entire project and change every single function that references the phone number variable.
Every time you create a Person object (or "instance of the Person class"), then each object has its own member data/variables.
Parent Classes
You also asked about parent classes. Let's imagine you wanted your address book to contain more detailed info, such as job titles & project info for each of your work buddies, and instant messaging addresses and photos for your other friends.
You could create two new classes from scratch Colleague and Friend, but that would be a bit wasteful - both would be almost identical (both have names, addresses, phone numbers etc.), so you're doing the same work twice.
Instead, what you would do is subclass Person twice. When you create the Colleague class, you specify it's a subclass of Person. It then gains (inherits) all the member data and methods from Person, so you just need to add in the bits that are specific to Colleague (i.e the member variables for job title, project info and the methods to get/fetch them). Likewise, with Friend.
In that case, Person is the parent class (or "superclass") of Colleague and Friend; and Colleague and Friend are the child classes (or "subclasses") of Person. (I wish I hadn't used people as my example, it's just getting confusing now!
)
Functions / Methods
Some important points about functions & methods.
Functions in C (or C++ or Objective C) take the following form;
draw(myWindow) ;
or
error = draw(myWindow) ;
or if it has several parameters:
error = draw(myWindow, size, position) ;
Methods
However, C doesn't have the concept of methods, while the syntax of C++ and Objective C methods are quite different.
In C++, the syntax for methods is similar to functions:
myWindow->draw() ;
and if it had several parameters:
myWindow->draw(size,position) ;
In Objective C, the syntax for methods is radically different:
[myWindow draw] ;
and if it had several parameters, it might be:
[myWindow drawWithSize: size atPosition: position] ;
Don't forget, even when writing an OO program in C++ or Objective C, you still can call C (non OOP) functions. For instance, up until recently, most of QuickTime functionality was available as a huge number of loose functions, rather than as a collection of classes as it is in Tiger. So, an Objective C, QuickTime program would have been a mixture of lots of Objective C method calls and QuickTime function calls with their different syntax.