Object Oriented Programming with PHP
Object orientated programming (OOP) is a commonly used term when discussing modern programming techniques. One of the things that makes humans stand out is the ability to categorise – we put objects into categories of similar type of function. For example, we have the category vechicle. Within this category, you have the different types of vehicle – car, bug, train, van. In the same bag, a llama is a type of animal. This analogy applies to programming – we create functions to do specific tasks and then group similar functions into classes. No only does this organise everything, but also allows a common access point for these similar functions.
OOP is a relatively new type of programming as far as PHP is concerned. PHP4 does not provide the full facilities a fully object orientated language such as a C++ provides as standard; but PHP5 improves upon this with much more OOP support. Olate Download 2.2 was programmed in a function based style with no classes at all. However, Olate Download 3.0 rewrites the entire application using classes. This allows updates to be made to the class functions without affecting the main code – you don’t necessarily need to know how a class/function does it’s job, just how to use that function.
Classes can’t do anything on their own. They must contain class functions, sometimes called methods. You define these functions just as if you were creating any normal function, however, you need to do it within the class structure.
Lets first create a class called cow. This class will then contain the functions of the cow. The first thing you do is to define the class:
|
If you found this post useful you may also want to check these out:
|
