Tuesday, 30 December 2008

Introduction to Objects

Before we can start programming in Objective-C, I'll first give a short explanation on the core fundamentals of OO.
You have first to think differently, you should remember only 1 concept :
"Everything is an object"
Let's look in the real world , you see all kinds of people in the street; you have Jan,Joe,Liz and Peter for example. Each of these people have characteristics (like length, weight, haircolor etc) and they do something (walking, reading, eating etc) eg they have a behaviour

So to summarize : objects have characteristics and behaviour.

Now to go one step further :
Jan, Joe, Liz and Peter are sharing the same types of characteristics and behaviour. We say that they belong to the same Class.

We can call this class Human. So Jan, Joe, Liz and Peter are all instances from the Class Human.
You can consider classes as factories out of which you instantiate objects (objects of a certain class).
Now you see that the class Human is a fat class, with lot of characteristics (or attributes) and behaviour (or functions, methods).
So sometimes you should refactor a class, in the case of the class Human we could factor out specific behaviour (and attributes) for man and woman .
This specific behaviour&attributes we organize in the classes Male and Female. These new classes are subclasses from Human. 

The class Human is what we call the superclass of Male and Female.

Next time we will see how objects communicate with each other (another important concept of OO) and the finally how all this is implemented in Objective-C

No comments:

Post a Comment