Programming languages are broadly divided into procedural languages:
languages which are not 100% OOP languages but which utilise some degree of OOP PHP and Ruby to name just two. Some programs are fully OO with the likes of Flash and Java. Personally, I think a procedural language such as PHP or Ruby is an excellent way for the novice to become better accustomed to OOP before immersing themselves completely.
OOP has a number of unique components, individual to it. Broadly speaking there are 2 main entities in OOP, and the way I imagine it as is a door and a key.
Data (which happens to be door) consists of a number of variables, which in the OOP world are called properties.
A collection and groups of Functions (which are the keys of OOP) with these functions used to modify the data, or properties. In the OOP world, these are called methods.
The collective name for properties and methods combined are classes and just to recap, methods are used to alter the properties. With me so far?
Whenever you define a class (bring it into existence in your code) unlike ordinary coding, you do not just create an object. Instead, you create a template for that object, so instead of creating an apple, you would have a basket of apples, or an apple tree, allowing you to reuse that “object” over and over again. Because you use objects derived from the template, you can then easily modify and alter the objects to your suiting.
Classes come in a hierarchy and for ease I will talk about PHP context. The classes are ranked according to their level of detail and sophistication and indeed precision, the standard class (which in PHP is called stdClass)is the most generic and broad of all the classes. Each of the classes beneath it will become steadily more narrow and specialised.
The class below a class is called the child, and the one on top is the parent. That is a clumsy way of describing it, but remember this basic rule, the child class is ALWAYS more specific, specialised and detailed than its parent class counterpart.
Code: Select all
class member_list {
var $members;
function update($members) {
...
}
}
The class keyword is used to create/initiate a new class. member_list is the name of the class and the curly brace { is used to open the class. Classes therefore, are quite similar in syntax and form to functions.
var$members is used to create a variable called members, and the var keyword in the context of classes is used to declare properties.
If you are confused by the 4 curly braces let me explain:
Code: Select all
class member_list { //Used to begin class
var $members;
function update($members) { //Used to begin function
...
} //End function
}//End class
Code: Select all
class member_list {
var $members= “Swan”;
function update($members) {
...
}
}