Do you know the Best explanation of Object Oriented Programming with a real...

elix1

New member
Oct 8, 2012
0
0
0
...life analogy to a PHP newbie? I still can't get it.
If a man is an object then what?????????
 
The idea behind object oriented programming is that you have classes which act like blueprints for objects. These classes define methods and properties of this class

Some real life analogies.

A car class could be defined like:
Class car{
String MFG;
String Make;
int year;
String color;
int maxSpeed;
int numOfDoors;
int numOfSeats;

//some methods it could have

speedUp(int speed)
slowDown(int speed)
steer(direction)
turnOnRadio(void)
turnOffRadio(void)
turnOnAC(int temp)
turnOffAC(void)
turnOnHeat(int temp)
turnOffHeat(void)
//and so on
}

The idea is that this class defines things about most cars in general and some things they can do.
Now when I create an object I would tell I have a red ford mustang 2002 and so on
This object belongs to me and I can change the properties of it or use its methods.

You could create multiple cars that belong to multiple people which have different colors, max speeds, number of doors, body styles.

I could make a class called gradebook and create a gradebook for each teacher, with a different number of students, names and grading scales. But each gradebook can calculate the letter grade, or the class average.

Most humans have two arms, two legs, two eyes and so on. They can walk, run, blink, talk, yell, sleep and so on. I can "instantify" myself and say I have two arms, brown eyes, brown hair, 5"6, and so on. I can "instantify" others with blond hair, blue eyes. With a "man" object I can make it run() to lower its weight() or goToWork() to improve its income.

Hope this helps!
 
Back
Top