![]() |
In order to transport this theoretical entrance into practice, we use a classic example here: an address.
An address normally consists of a name, a street, a ZIP code and the city as well as the country (in some countries there is also a province or a federal state, but we leave that unconsidered here). Logical you might say, but indeed it is not that logic.
Normally you would probably define five variables ($Name, $Street, $ZIP, $City and $Country) of different types (string, integer etc.) and allocate any values to these variables and work with them. But it is not evident for the programming language resp. the computer that and how these four variables are related. For instance, if you change the content of $city, the content of $ZIP has to change in effect. But in classic procedural programming something like this is not done automatically, but you have to take care of it. If you leave this undone, e. g., because you have lost overview in thousands of lines of code, dangerous data inconsistencies may occur.
In the object-oriented world you define a new variable type „address“ first. We designate the address as class. Like there are different pupils in a grade of school (who have been logically consolidated in one unit, e. g., because of their common age), there are different attendants in our class „address“ as well, namely our ex-variables $Name, $Street, $ZIP, $City and $Country. Syntactical such a class is defined in PHP as follows:
Class Adresse
{
var $Name;
var $Strasse;
var $PLZ;
var $Ort;
var $Land;
}