No no, you don't steer clear. All of us, at some point, were completely baffled by OOP.
And if people didn't answer, it's not because they don't want to explain it... It's just not easy to explain.
Think of it as a sentence. A class is a bunch of adjectives and verbs, and an object is a noun. A noun is just a noun until it has a description and a purpose.
The variables of the class are the adjectives.
The functions of the class are the verbs.
So, lets say we have a class called.. builder. His adjectives are... strength, work ethic, and intelligence.
The builder class has the verbs: plan, build, and take a break.
So, here's our class:
Code: Select all
class Builder
{
private $strength, $workEthic, $intelligence;
public function __construct(); // Constructor
public function Plan();
public function Build();
public function TakeBreak();
}
Then, we'd make a noun of type "Builder."
And you could make $Joe do stuff.
Code: Select all
$Joe->Plan();
$Joe->Build();
$Joe->TakeBreak();
The trick about classes is that everything that you make $Joe do, $Joe does based on HIS adjectives. So, if Joe is weak, he'd get less work done, but if he is intelligent, he'd have higher quality planning.
You'd create the verbs (functions) to reflect the way that everything should be done based on the adjectives (member variables).
The purpose of classes is to give objects tasks, give them data to do the tasks with, and have them communicate the results to either the application or to other objects.
Think of it as a business. The separation of tasks gets work done faster, more efficiently, and much more neatly.